func main() { var port int var host string flag.IntVar(&port, "port", 2489, "TCP port number") flag.StringVar(&host, "host", "localhost", "Remote hostname") confPath, err := homedir.Expand("~/.config/remote-open.toml") if err != nil { panic(err) } if args, err := conflag.ArgsFrom(confPath); err == nil { flag.CommandLine.Parse(args) } flag.Parse() conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", host, port)) if err != nil { panic(err) } defer conn.Close() fmt.Fprintf(conn, flag.Arg(0)) conn.Write([]byte{'\000'}) body, err := ioutil.ReadAll(conn) if err != nil { panic(err) } if len(body) != 0 { panic(string(body)) } }
func main() { var port int var allow string flag.IntVar(&port, "port", 2489, "TCP port number") flag.StringVar(&allow, "allow", "0.0.0.0/0,::0", "Allowed IP address") confPath, err := homedir.Expand("~/.config/remote-opend.toml") if err != nil { panic(err) } if args, err := conflag.ArgsFrom(confPath); err == nil { flag.CommandLine.Parse(args) } flag.Parse() firewall, err = NewFirewall(allow) if err != nil { panic(err) } l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { panic(err) } defer l.Close() for { conn, err := l.Accept() if err != nil { panic(err) } go handle(conn) } }
func main() { args, err := conflag.ArgsFrom(os.Args[1], os.Args[2:]...) if err != nil { fmt.Printf("%v\n", err) return } fmt.Printf("%v\n", args) }
func (p PlatinumSearcher) Run(args []string) int { parser := newOptionParser(&opts) conflag.LongHyphen = true conflag.BoolValue = false for _, c := range []string{filepath.Join(home.Dir(), ".ptconfig.toml"), ".ptconfig.toml"} { if args, err := conflag.ArgsFrom(c); err == nil { parser.ParseArgs(args) } } args, err := parser.ParseArgs(args) if err != nil { return ExitCodeError } if opts.Version { fmt.Printf("pt version %s\n", version) return ExitCodeOK } if len(args) == 0 && !opts.SearchOption.EnableFilesWithRegexp { parser.WriteHelp(p.Err) return ExitCodeError } if !terminal.IsTerminal(os.Stdout) { opts.OutputOption.EnableColor = false opts.OutputOption.EnableGroup = false } if p.givenStdin() && p.noRootPathIn(args) { opts.SearchOption.SearchStream = true } if opts.SearchOption.EnableFilesWithRegexp { args = append([]string{""}, args...) } if opts.OutputOption.Count { opts.OutputOption.Before = 0 opts.OutputOption.After = 0 opts.OutputOption.Context = 0 } search := search{ roots: p.rootsFrom(args), out: p.Out, } if err = search.start(p.patternFrom(args)); err != nil { fmt.Fprintf(p.Err, "%s\n", err) return ExitCodeError } return ExitCodeOK }
func (c *CLI) parse(args []string) error { flags := c.flags() confPath, err := homedir.Expand("~/.config/lemonade.toml") if err == nil { if confArgs, err := conflag.ArgsFrom(confPath); err == nil { flags.Parse(confArgs) } } var arg string err = flags.Parse(args[1:]) if err != nil { return err } if c.Type == PASTE || c.Type == SERVER { return nil } for 0 < flags.NArg() { arg = flags.Arg(0) err := flags.Parse(flags.Args()[1:]) if err != nil { return err } } if c.Help { return nil } if arg != "" { c.DataSource = arg } else { b, err := ioutil.ReadAll(c.In) if err != nil { return err } c.DataSource = string(b) } return nil }
func main() { opts.Color = opts.SetEnableColor opts.NoColor = opts.SetDisableColor opts.EnableColor = true opts.SkipVcsIgnore = opts.SkipVcsIgnores parser := flags.NewParser(&opts, flags.Default) parser.Name = "pt" parser.Usage = "[OPTIONS] [PATTERN] [PATH]" conflag.LongHyphen = true conflag.BoolValue = false for _, c := range []string{filepath.Join(home.Dir(), ".ptconfig.toml"), ".ptconfig.toml"} { if args, err := conflag.ArgsFrom(c); err == nil { parser.ParseArgs(args) } } args, err := parser.Parse() if err != nil { os.Exit(1) } if opts.Version { fmt.Printf("%s\n", version) os.Exit(0) } if len(args) == 0 && opts.FilesWithRegexp == "" { parser.WriteHelp(os.Stdout) os.Exit(1) } opts.SearchStream = false if opts.FilesWithRegexp == "" && len(args) == 1 { fi, err := os.Stdin.Stat() if runtime.GOOS == "windows" { if err == nil { opts.SearchStream = true opts.NoGroup = true } } else { if err != nil { os.Exit(1) } mode := fi.Mode() if (mode&os.ModeNamedPipe != 0) || mode.IsRegular() { opts.SearchStream = true opts.NoGroup = true } } } var roots = []string{"."} if (opts.FilesWithRegexp == "" && len(args) >= 2) || (opts.FilesWithRegexp != "" && len(args) > 0) { roots = []string{} paths := args[1:] if opts.FilesWithRegexp != "" { paths = args } for _, root := range paths { root = strings.TrimRight(root, "\"") _, err := os.Lstat(root) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) os.Exit(1) } roots = append(roots, root) } } opts.Proc = runtime.NumCPU() if !terminal.IsTerminal(os.Stdout) { if !opts.ForceColor { opts.EnableColor = false } opts.NoGroup = true } if opts.Context > 0 { opts.Before = opts.Context opts.After = opts.Context } pattern := "" if opts.FilesWithRegexp == "" && len(args) > 0 { pattern = args[0] } if opts.WordRegexp { opts.Regexp = true pattern = "\\b" + pattern + "\\b" } start := time.Now() searcher := pt.PlatinumSearcher{roots, pattern, &opts} err = searcher.Search() if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) os.Exit(1) } if opts.Stats { elapsed := time.Since(start) fmt.Printf("%d Files Searched\n", pt.FilesSearched) fmt.Printf("%s Elapsed\n", elapsed) } if pt.FileMatchCount == 0 && pt.MatchCount == 0 { os.Exit(1) } }