Parse the command line entry.
@param cl commandLine
@param args args passed in
@return commandLine
169435
CommandLine parse(DefaultCommandLine cl, String[] args) {
        parseInternal(cl, args, true);
        return cl;
    }
685572
public static CliArguments parse(String[] args) {
        CliArguments arguments = new CliArguments();
        if (args != null) {
            CmdLineParser parser = new CmdLineParser(arguments);
            try {
                parser.parseArgument(args);
            } catch (CmdLineException e) {
                // ignore
            }

            arguments.usageMode = false;
            for (String arg : args) {
                for (int i = 0; i < USAGE_TOKENS.length; i++) {
                    String usageToken = USAGE_TOKENS[i];
                    if (usageToken.equalsIgnoreCase(arg)) {
                        arguments.usageMode = true;
                        break;
                    }
                }
            }
        }
        return arguments;
    }
676920
public String[] init(String[] argv, int min, int max,
                       Collection<CommandLineParser.Option> options)
    throws IOException, SAXException {
    // parse command line
    parser = new CommandLineParser();
    parser.setMinimumArguments(min);
    parser.setMaximumArguments(max);
    parser.registerOption(new CommandLineParser.BooleanOption("reindex", 'I'));
    if (options != null)
      for (CommandLineParser.Option option : options)
        parser.registerOption(option);

    try {
      argv = parser.parse(argv);
    } catch (CommandLineParser.CommandLineParserException e) {
      System.err.println("ERROR: " + e.getMessage());
      usage();
      System.exit(1);
    }

    // do we need to reindex?
    boolean reindex = parser.getOptionState("reindex");

    // load configuration
    config = ConfigLoader.load(argv[0]);
    database = config.getDatabase(reindex); // overwrite iff reindex
    if (database.isInMemory())
      reindex = true; // no other way to do it in this case

    // reindex, if requested
    if (reindex)
      reindex(config, database);

    return argv;
  }
1241530
public CommandLine parse(String[] args) throws ParseException {
        // create the command line parser
        GnuParser parser = new GnuParser();
        Options buildCommandLineOptions = buildCommandLineOptions();
        CommandLine cmd = null;
        try {
            cmd = parser.parse(buildCommandLineOptions, args);
            if (cmd.getOptions().length == 0 || cmd.hasOption("h")) {
                printHelp(buildCommandLineOptions);
                return null;
            }
            if (cmd.getArgList().isEmpty()) {
                throw new MissingOptionException("The 'inputPage' is mandatory! No page to run given");
            }
            return cmd;
        } catch (MissingOptionException e) {
            if (args == null || args.length == 0) {
                logger.debug("option --help has been set. Ignoring Missing Option exception");
                printHelp(buildCommandLineOptions);
                return cmd;
            }
            for (String arg : args) {
                if (StringUtils.equals("-h", arg) || StringUtils.equals("--help", arg)) {
                    logger.debug("option --help has been set. Ignoring Missing Option exception");
                    printHelp(buildCommandLineOptions);
                    return null;
                }
            }
            handleParseException(buildCommandLineOptions, e);
            throw e;
        } catch (ParseException e) {
            handleParseException(buildCommandLineOptions, e);
            throw e;
        }
    }
348213
public static String parseCommandArgs(String commandLine, final CommandLineParser.CallbackHandler handler) throws CommandFormatException {
        if(commandLine == null) {
            return null;
        }
        final ParsingStateCallbackHandler callbackHandler = getCallbackHandler(handler);
        return StateParser.parse(commandLine, callbackHandler, ArgumentListState.INSTANCE);
    }
586295
public Quidem parse() throws ParseException {
    final List<Quidem.ConnectionFactory> factories = new ArrayList<>();
    final List<CommandHandler> commandHandlers = new ArrayList<>();
    final Map<String, String> envMap = new LinkedHashMap<>();
    int i;
    for (i = 0; i < args.size();) {
      String arg = args.get(i);
      if (arg.equals("--help")) {
        usage();
        throw new ParseException(0);
      }
      if (arg.equals("--db")) {
        if (i + 4 >= args.size()) {
          throw error("Insufficient arguments for --db");
        }
        final String name = args.get(i + 1);
        final String url = args.get(i + 2);
        final String user = args.get(i + 3);
        final String password = args.get(i + 4);
        factories.add(new SimpleConnectionFactory(name, url, user, password));
        i += 5;
        continue;
      }
      if (arg.equals("--var")) {
        if (i + 3 >= args.size()) {
          throw error("Insufficient arguments for --var");
        }
        final String name = args.get(i + 1);
        final String value = args.get(i + 2);
        envMap.put(name, value);
        i += 3;
        continue;
      }
      if (arg.equals("--factory")) {
        if (i + 1 >= args.size()) {
          throw error("Insufficient arguments for --factory");
        }
        final String className = args.get(i + 1);
        final Class<?> factoryClass;
        try {
          factoryClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
          throw error("Factory class " + className + " not found");
        }
        Quidem.ConnectionFactory factory;
        try {
          factory = (Quidem.ConnectionFactory) factoryClass.newInstance();
        } catch (InstantiationException e) {
          throw error("Error instantiating factory class " + className);
        } catch (IllegalAccessException e) {
          throw error("Error instantiating factory class " + className);
        } catch (ClassCastException e) {
          throw error("Error instantiating factory class " + className);
        }
        factories.add(factory);
        i += 2;
        continue;
      }
      if (arg.equals("--command-handler")) {
        if (i + 1 >= args.size()) {
          throw error("Insufficient arguments for --command-handler");
        }
        final String className = args.get(i + 1);
        final Class<?> factoryClass;
        try {
          factoryClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
          throw error("Factory class " + className + " not found");
        }
        CommandHandler commandHandler;
        try {
          commandHandler = (CommandHandler) factoryClass.newInstance();
        } catch (InstantiationException e) {
          throw error("Error instantiating command-handler class " + className);
        } catch (IllegalAccessException e) {
          throw error("Error instantiating command-handler class " + className);
        } catch (ClassCastException e) {
          throw error("Error instantiating command-handler class " + className);
        }
        commandHandlers.add(commandHandler);
        i += 2;
        continue;
      }
      break;
    }
    if (i + 2 > args.size()) {
      throw error("Insufficient arguments: need inFile and outFile");
    }
    final File inFile = new File(args.get(i));
    final File outFile = new File(args.get(i + 1));
    final Reader reader;
    try {
      reader = new LineNumberReader(new FileReader(inFile));
    } catch (FileNotFoundException e) {
      throw new RuntimeException("Error opening input " + inFile, e);
    }
    final Writer writer;
    try {
      writer = new FileWriter(outFile);
    } catch (IOException e) {
      throw new RuntimeException("Error opening output " + outFile, e);
    }

    factories.add(new UnsupportedConnectionFactory());
    final ChainingConnectionFactory connectionFactory =
        new ChainingConnectionFactory(factories);
    final ChainingCommandHandler commandHandler =
        new ChainingCommandHandler(commandHandlers);

    final Function<String, Object> env = envMap::get;
    final Quidem.Config config = Quidem.configBuilder()
        .withReader(reader)
        .withWriter(writer)
        .withEnv(env)
        .withConnectionFactory(connectionFactory)
        .withCommandHandler(commandHandler)
        .build();
    return new Quidem(config);
  }
181428
public static RunOptions parseRunCommand(String[] args) throws CliArgsException {
		try {
			DefaultParser parser = new DefaultParser();
			CommandLine line = parser.parse(RUN_OPTIONS, args, true);
			return new RunOptions(line);
		}
		catch (ParseException e) {
			throw new CliArgsException(e.getMessage());
		}
	}
1219109
def parse_args(self, args=None, namespace=None):
        
        self._expand_prefixed_files(args)
        return super(CLICommandParser, self).parse_args(args)
1003678
public static String parseOperationRequest(String commandLine, final CommandLineParser.CallbackHandler handler) throws CommandFormatException {
        SubstitutedLine sl = parseOperationRequestLine(commandLine, handler, null);
        return sl == null ? null : sl.getSubstitued();
    }
199356
def parse_command_line
      begin
        opts = GetoptLong.new(
          [ '--tag', '-t', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--tag-use-and', '-a', GetoptLong::NO_ARGUMENT ],
          [ '--tag-use-or', '-o', GetoptLong::NO_ARGUMENT ],
          [ '--array', '-r', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--deployment', '-e', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--script', '-s', GetoptLong::OPTIONAL_ARGUMENT ],
          [ '--ssh', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
          [ '--input', '-i', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--set-template', '-m', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--set-tag', '-w', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--report', '-b', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--progress', '-p', GetoptLong::NO_ARGUMENT ],
          [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
          [ '--quiet', '-q', GetoptLong::NO_ARGUMENT ],
          [ '--noprompt', '-z', GetoptLong::NO_ARGUMENT ],
          [ '--concurrency', '-c', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--delay', '-d', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--retry', '-y', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--hold', '-7', GetoptLong::NO_ARGUMENT ],
          [ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ],
          [ '--limit', '-l', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--version', '-1', GetoptLong::NO_ARGUMENT ],
          [ '--chimpd', '-f', GetoptLong::OPTIONAL_ARGUMENT ],
          [ '--chimpd-wait-until-done', '-j', GetoptLong::NO_ARGUMENT ],
          [ '--dont-check-templates', '-0', GetoptLong::NO_ARGUMENT ],
          [ '--ignore-errors', '-9', GetoptLong::NO_ARGUMENT ],
          [ '--ssh-user', '-u', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
          [ '--group', '-g', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--group-type', '-2', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--group-concurrency', '-3', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--timing-log', '-4', GetoptLong::REQUIRED_ARGUMENT ],
          [ '--timeout', '-5',  GetoptLong::REQUIRED_ARGUMENT ],
          [ '--noverify', '-6', GetoptLong::NO_ARGUMENT ],
          [ '--exact-matching', '-8', GetoptLong::NO_ARGUMENT ],
          [ '--job-notes', '-k', GetoptLong::OPTIONAL_ARGUMENT ]
        )

        opts.each do |opt, arg|
          case opt
            when '--help', '-h'
              help
              exit 0
            when '--tag', '-t'
              @tags << arg
            when '--tag-use-and', '-a'
              @match_all = true
            when '--tag-use-or', '-o'
              @match_all = false
            when '--array', '-a'
              @array_names << arg
            when '--deployment', '-e'
              @deployment_names << arg
            when '--template', '-m'
              @template = arg
            when '--script', '-s'
              set_action(:action_rightscript)
              if arg == ""
                # Empty but not nil means show list of operational scripts to choose from
                @script = ""
              else
                @script = arg
              end
            when '--ssh', '-x'
              set_action(:action_ssh)
              @break_array_into_instances = true
              if arg == ""
                print "Enter SSH command line to execute: "
                @ssh = gets.chomp
              else
                @ssh = arg
              end
            when '--ssh-user', '-u'
              @ssh_user = arg
            when '--input', '-i'
              arg =~ /(.+)=(.+)/
              @inputs[$1]=$2
            when '--set-template', '-m'
              set_action(:action_set)
              @template = arg
            when '--set-tag', '-w'
              set_action(:action_set)
              @set_tags << arg
            when '--report', '-b'
              set_action(:action_report)
              @report = arg
              @@verbose = false
              @@quiet = true
              @break_array_into_instances = true
              @concurrency = 5 if @concurrency == 1
            when '--progress', '-p'
              @progress = @progress ? false : true
            when '--noprompt', '-z'
              @prompt = false
            when '--concurrency', '-c'
              @concurrency = arg.to_i
            when '--delay', '-d'
              @delay = arg.to_i
            when '--hold', '-7'
              @hold = true
            when '--retry', '-y'
              @retry_count = arg.to_i
            when '--limit', '-l'
              @limit_start, @limit_end = arg.split(',')
            when '--verbose', '-v'
              @@verbose = true
              Log.threshold = Logger::DEBUG
            when '--quiet', '-q'
              @@quiet = true
            when '--dont-check-templates', '-0'
              @dont_check_templates_for_script = true
            when '--version'
              puts VERSION
              exit 0
            when '--chimpd'
              @use_chimpd = true
              unless arg.empty?
                if arg =~ /[\d]+\.[\d]+\.[\d]+\.[\d]+:[\d]+/
                  @chimpd_host, @chimpd_port = arg.split(':')
                  @chimpd_port = @chimpd_port.to_i
                else
                  @chimpd_port = arg.to_i
                end
              end
            when '--chimpd-wait-until-done'
              @use_chimpd = true
              @chimpd_wait_until_done = true
            when '--dry-run', '-n'
              @dry_run = true
            when '--ignore-errors', '-9'
              @ignore_errors = true
            when '--group', '-g'
              @group = arg.to_sym
            when '--group-type'
              @group_type = arg.to_sym
            when '--group-concurrency'
              @group_concurrency = arg.to_i
            when '--job-notes'
              @job_notes = arg
            when '--timing-log'
              @timing_log = arg
            when '--timeout'
              @timeout = arg
            when '--noverify'
              @verify = false
            when '--exact-matching'
              @exact = true
          end
        end

        if @use_chimpd && ( @script.nil? || @script.empty? )
          if @chimpd_wait_until_done == false
            puts "#######################################################"
            puts "ERROR: --script cannot be empty when sending to chimpd"
            puts "#######################################################"
            exit 1
          end
        end


      rescue GetoptLong::InvalidOption => ex
        help
        exit 1
      end

      #
      # Before we're totally done parsing command line options,
      # let's make sure that a few things make sense
      #
      if @group_concurrency > @concurrency
        @concurrency = @group_concurrency
      end
    end
769216
def _parse_args(cls):
        
        cls.parser = argparse.ArgumentParser()
        cls.parser.add_argument(
            "symbol", help="Symbol for horizontal line", nargs="*")
        cls.parser.add_argument(
            "--color", "-c", help="Color of the line", default=None, nargs=1)
        cls.parser.add_argument(
            "--version", "-v", action="version", version="0.13")

        return cls.parser
418553
public static SubstitutedLine parseHeadersLine(String commandLine, final CommandLineParser.CallbackHandler handler, final CommandContext ctx) throws CommandFormatException {
        if (commandLine == null) {
            return null;
        }
        final ParsingStateCallbackHandler callbackHandler = getCallbackHandler(handler);
        return StateParser.parseLine(commandLine, callbackHandler, HeaderListState.INSTANCE, ctx);
    }
578629
protected void processSystemArg(DefaultCommandLine cl, String arg) {
        int i = arg.indexOf("=");
        String name = arg.substring(2, i);
        String value = arg.substring(i + 1, arg.length());
        cl.addSystemProperty(name, value);
    }
373224
public static String parse(String commandLine, final CommandLineParser.CallbackHandler handler) throws CommandFormatException {
        return parse(commandLine, handler, true);
    }
206291
public static String parse(String str, final CommandLineParser.CallbackHandler handler, ParsingState initialState) throws CommandFormatException {
        if(str == null) {
            return null;
        }
        final ParsingStateCallbackHandler callbackHandler = getCallbackHandler(handler);
        return StateParser.parse(str, callbackHandler, initialState);
    }
252971
public List<Entry> parse(String[] argv) {
        optind = -1;

        List<Entry> ret = new ArrayList<Entry>();

        int idx = 0;
        while (idx < argv.length) {
            if (argv[idx].equals("--")) {
                // End of options!
                ++idx;
                break;
            }

            if (argv[idx].charAt(0) != '-') {
                // End of options
                break;
            }


            if (argv[idx].startsWith("--")) {
                idx = parseLongOption(argv, ret, idx);
            } else if (argv[idx].startsWith("-")) {
                idx = parseShortOption(argv, ret, idx);
            } else {
                break;
            }
            ++idx;
        }

        if (idx != argv.length) {
            optind = idx;
        }

        return ret;
    }
736467
public Settings parse(String[] arguments) throws CommandLineException {

		Settings out = new Settings();

		if (arguments != null) {

			// each argument is either a option or a option value
			CommandOption option = null;

			for (String argument : arguments) {

				if (isOption(argument)) { // is this an option or an argument ... ?

					option = findOption(argument);

					if (option != null && !option.hasArguments()) {
						// this is a no arg option ... add it to list (we might override this in the next step)
						out.put(option.getSetting(), option.parse(argument));
					}
					continue;
				}

				if (option == null) {
					throw new CommandLineException("Unknown command line option: " + argument);
				}

				Object value = option.parse(argument);
				out.put(option.getSetting(), value);
			}
		}

		// check if ConfigFileOption is provided and given
		CommandOption config = builder.getConfigFileOption();

		// create copy of builder to override defaults if needed
		CommandBuilder defaults = new CommandBuilder(builder.get());

		if (config != null) {

			String file = (String) out.get(config.getSetting()); // is provided?
			if (file != null) {
				ConfigFileReader reader = new ConfigFileReader();
				Settings configSettings = reader.load(file, builder);

				// override default with read config
				defaults.setDefaults(configSettings);

				// remove config setting from output
				out.remove(config.getSetting());
			}
		}

		// add default options if any
		for (CommandOption option : defaults.get()) {

			if (!(option instanceof ConfigFileOption) &&
				!out.containsKey(option.getSetting())) {
				out.put(option.getSetting(), option.getDefault());
			}
		}

		return out;
	}