// Parses the command-line arguments, exiting the process appropriately on
// errors or if usage is printed.
173824
func Parse(cmd interface{}, opts ...parseOpt) {
	opts = append([]parseOpt{Program(filepath.Base(os.Args[0]))}, opts...)
	ParseArgs(cmd, os.Args[1:], opts...)
}
239156
func (c *Command) ParseFlags(args []string) error {
	if c.DisableFlagParsing {
		return nil
	}

	if c.flagErrorBuf == nil {
		c.flagErrorBuf = new(bytes.Buffer)
	}
	beforeErrorBufLen := c.flagErrorBuf.Len()
	c.mergePersistentFlags()

	//do it here after merging all flags and just before parse
	c.Flags().ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist)

	err := c.Flags().Parse(args)
	// Print warnings if they occurred (e.g. deprecated flag messages).
	if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil {
		c.Print(c.flagErrorBuf.String())
	}

	return err
}
250907
func processArgs() (cfg *etcd.ClientConfig, op int, data []string, err error) {
	var task []string

	// default args
	fileConfig := &etcd.Config{}
	op = Put

	if len(os.Args) > 2 {
		if os.Args[1] == "--cfg" {
			err = config.ParseConfigFromYamlFile(os.Args[2], fileConfig)
			if err != nil {
				return
			}
			cfg, err = etcd.ConfigToClient(fileConfig)
			if err != nil {
				return
			}

			task = os.Args[3:]
		} else {
			task = os.Args[1:]
		}
	} else {
		return cfg, 0, nil, fmt.Errorf("incorrect arguments")
	}

	if len(task) < 2 || (task[0] == "put" && len(task) < 4) {
		return cfg, 0, nil, fmt.Errorf("incorrect arguments")
	}

	if task[0] == "delete" {
		op = Delete
	} else if task[0] == "puttxn" {
		op = PutTxn
	}

	return cfg, op, task[1:], nil
}
841326
func parseArgs(argv []string) (string, []string) {
	if len(argv) == 1 {
		if argv[0] == "--help" || argv[0] == "-h" {
			// rearrange "deis --help" as "deis help"
			argv[0] = "help"
		} else if argv[0] == "--version" || argv[0] == "-v" {
			// rearrange "deis --version" as "deis version"
			argv[0] = "version"
		}
	}

	if len(argv) >= 2 {
		// Rearrange "deis help <command>" to "deis <command> --help".
		if argv[0] == "help" || argv[0] == "--help" || argv[0] == "-h" {
			argv = append(argv[1:], "--help")
		}
	}

	if len(argv) > 0 {
		argv[0] = replaceShortcut(argv[0])

		index := strings.Index(argv[0], ":")

		if index != -1 {
			command := argv[0]
			return command[:index], argv
		}

		return argv[0], argv
	}

	return "", argv
}
127969
func GetArgs(line string, options ...GetArgsOption) (args []string) {
	scanner := getScanner(line, options...)
	args, _, _ = scanner.GetTokensN(0)
	return
}
700551
func Run(args []string) error {
	opt := newOption(ErrorWriter, flag.ExitOnError)
	if e := opt.parse(args); e != nil {
		Usage()
		PrintDefaults(flag.ExitOnError)
		return fmt.Errorf("%v, %v", CommandName, e)
	}
	return command(opt)
}
1093623
func (o *Opts) ParseArgs(args []string) *Opts {
	if err := o.Process(args); err != nil {
		fmt.Fprintf(os.Stderr, err.Error()+"\n")
		os.Exit(1)
	}
	return o
}
720363
func (p Program) ArgsWith(args []string) []string {
	if p.Args == nil || len(p.Args) == 0 {
		return args
	}
	if len(args) == 0 {
		return p.Args
	}
	return append(p.Args, args...)
}
617047
func (c *Config) Args() []string {
	args := []string{}
	for _, p := range c.Params {
		args = append(args, p.Args()...)
	}
	return args
}
123886
func Parse() string {
	selected := MustParse(CommandLine.Parse(os.Args[1:]))
	if selected == "" && CommandLine.cmdGroup.have() {
		Usage()
		CommandLine.terminate(0)
	}
	return selected
}
804712
func ParseCommand(line string) *Command {
	words := strings.Split(line, " ")
	command := strings.ToUpper(words[0])
	args := strings.Join(words[1:len(words)], " ")

	return &Command{
		verb: command,
		args: args,
		orig: line,
	}
}
659074
func Parse(doc string, argv []string, help bool, version string, optionsFirst bool, exit ...bool) (map[string]interface{}, error) {
	exitOk := true
	if len(exit) > 0 {
		exitOk = exit[0]
	}
	p := &Parser{
		OptionsFirst:  optionsFirst,
		SkipHelpFlags: !help,
	}
	if exitOk {
		p.HelpHandler = PrintHelpAndExit
	} else {
		p.HelpHandler = PrintHelpOnly
	}
	return p.parse(doc, argv, version)
}
1103324
func ParsePathsFromArgs() {
	flag.Parse()
	for _, dir := range flag.Args() {
		var conf loader.Config
		conf.ParserMode = parser.ParseComments
		conf.ImportWithTests(dir)
		prog, err := conf.Load()
		if err != nil {
			panic(err)
		}

		r := renamer{prog, map[*token.File]bool{}}
		r.parse()
		if !*dryRun {
			r.write()
		}
	}
}
763642
func main() {
	if len(os.Args) < 2 {
		// Only have the command name. Need to print out help text.
		log.Printf("Usage: %v '$['json']['path']['string']' a.json...\n", os.Args[0])
		os.Exit(1)
	}
	filter, err := jsonpath.Parse(os.Args[1])
	if err != nil {
		log.Printf("Usage: %v '$['json']['path']['string']' a.json...\n", os.Args[0])
		log.Printf("Got the following error Parsing %v : %v\n", os.Args[1], err)
		os.Exit(1)
	}
	if len(os.Args) == 2 {
		// use stdinput
		data, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			log.Printf("Usage: %v '$['json']['path']['string']' a.json...\n", os.Args[0])
			log.Printf("Got the following error Reading from STDIN  %v\n", err)
			os.Exit(1)
		}
		d, err := applyFilter(filter, data)
		if err != nil {
			log.Printf("Usage: %v '$['json']['path']['string']' a.json...\n", os.Args[0])
			log.Printf("Got the following error Applying filter  %v\n", err)
			os.Exit(1)
		}
		data, err = json.MarshalIndent(d, "", "   ")
		if err != nil {
			log.Printf("Usage: %v '$['json']['path']['string']' a.json...\n", os.Args[0])
			log.Printf("Got the following error Printing out json %v\n", err)
			os.Exit(1)
		}
		fmt.Println(string(data))
	}
	for _, filename := range os.Args[2:] {
		data, err := ioutil.ReadFile(filename)
		if err != nil {
			log.Printf("Got the following error Reading from %v  %v\n", filename, err)
			continue
		}
		d, err := applyFilter(filter, data)
		if err != nil {
			log.Printf("Got the following error Applying filter for %v  %v\n", filename, err)
			continue
		}
		data, err = json.MarshalIndent(d, "", "   ")
		if err != nil {
			log.Printf("Got the following error Trying to print result for file %v  %v\n", filename, err)
			continue
		}
		fmt.Println(string(data))
	}

}
294938
func CommandLineToArgv(commandLine string) ([]string, error) {
	var argc int32

	argsPtr, err := windows.UTF16PtrFromString(commandLine)
	if err != nil {
		return nil, err
	}

	argv, err := windows.CommandLineToArgv(argsPtr, &argc)
	if err != nil {
		return nil, err
	}
	defer windows.LocalFree(windows.Handle(uintptr(unsafe.Pointer(argv))))

	newArgs := make([]string, argc)
	for i, v := range (*argv)[:argc] {
		newArgs[i] = string(windows.UTF16ToString((*v)[:]))
	}

	return newArgs, nil
}
1221937
func Parse(v interface{}) ([]string, error) {
	if command, _, err := generateCommand(v, true); err == nil {
		return command, err
	} else {
		return nil, err
	}
}
659546
func WithProcessArgs(args ...string) SpecOpts {
	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
		setProcess(s)
		s.Process.Args = args
		return nil
	}
}