To be called inside OptionParser block
 Extract the option in the command line using the OptionParser and map it to the out map.
 @return [Hash] Where the options shall be extracted
519324
def option_defaults
      out = {}
      @specific_options.each do |option|
        option.load_default(out)
      end

      @general_options.each do |_cls, option|
        out.merge! option.class.option_defaults
      end
      out
    end
237746
def ParseOptions(self, options):
    
    # The extraction options are dependent on the data location.
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=['data_location'])

    self._ReadParserPresetsFromFile()

    # The output modules options are dependent on the preferred language
    # and preferred time zone options.
    self._ParseTimezoneOption(options)

    argument_helper_names = [
        'artifact_definitions', 'hashers', 'language', 'parsers']
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=argument_helper_names)

    self.list_hashers = self._hasher_names_string == 'list'
    self.list_language_identifiers = self._preferred_language == 'list'
    self.list_parsers_and_plugins = self._parser_filter_expression == 'list'

    # Check the list options first otherwise required options will raise.
    if (self.list_hashers or self.list_language_identifiers or
        self.list_parsers_and_plugins or self.list_timezones):
      return

    # Check output modules after the other listable options, otherwise
    # it could raise with "requires an output file".
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=['output_modules'])

    self.list_output_modules = self._output_format == 'list'
    if self.list_output_modules:
      return

    self._ParseInformationalOptions(options)

    argument_helper_names = ['extraction', 'status_view']
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=argument_helper_names)

    self._ParseLogFileOptions(options)

    self._ParseStorageMediaOptions(options)

    self._ParsePerformanceOptions(options)
    self._ParseProcessingOptions(options)

    self._storage_file_path = getattr(options, 'storage_file', None)
    if not self._storage_file_path:
      self._storage_file_path = self._GenerateStorageFileName()

    self._output_filename = getattr(options, 'write', None)

    if not self._output_filename:
      raise errors.BadConfigOption((
          'Output format: {0:s} requires an output file '
          '(-w OUTPUT_FILE)').format(self._output_format))

    if os.path.exists(self._output_filename):
      raise errors.BadConfigOption(
          'Output file already exists: {0:s}.'.format(self._output_filename))

    self._EnforceProcessMemoryLimit(self._process_memory_limit)

    self._output_module = self._CreateOutputModule(options)
157666
private boolean processLine(final CommandLine line, final Options options)
            throws Exception {
        if (line.hasOption(OPTION_VERSION)) {
            log.info(getVersion(true));
            return false;
        }
        if (line.hasOption(OPTION_HELP)) {
            produceHelp(options);
            return false;
        }
        if (line.hasOption(OPTION_INPUT)) {
            setXsdInput(line.getOptionValue(OPTION_INPUT).trim());
        }
        if (line.hasOption(OPTION_OUTPUT)) {
            setOutput(line.getOptionValue(OPTION_OUTPUT).trim());
        }
        if (line.hasOption(OPTION_AVRO_NAMESPACE_PREFIX)) {
            setAvroNamespacePrefix(line.getOptionValue(OPTION_AVRO_NAMESPACE_PREFIX).trim());
        }

        return true;
    }
654632
def parser
      @parser ||= OptionParser.new do |opts|
        opts.banner = USAGE

        opts.on('-b', '--build-id BuildID', 'BuildID[sha1] of libc.') do |b|
          @options[:build_id] = b
        end

        opts.on('-f', '--[no-]force-file', 'Force search gadgets in file instead of build id first.') do |f|
          @options[:force_file] = f
        end

        opts.on('-l', '--level OUTPUT_LEVEL', Integer, 'The output level.',
                'OneGadget automatically selects gadgets with higher successful probability.',
                'Increase this level to ask OneGadget show more gadgets it found.',
                'Default: 0') do |l|
          @options[:level] = l
        end

        opts.on('-n', '--near FUNCTIONS/FILE', 'Order gadgets by their distance to the given functions'\
                ' or to the GOT functions of the given file.') do |n|
          @options[:near] = n
        end

        opts.on('-r', '--[no-]raw', 'Output gadgets offset only, split with one space.') do |v|
          @options[:raw] = v
        end

        opts.on('-s', '--script exploit-script', 'Run exploit script with all possible gadgets.',
                'The script will be run as \'exploit-script $offset\'.') do |s|
          @options[:script] = s
        end

        opts.on('--info BuildID', 'Show version information given BuildID.') do |b|
          @options[:info] = b
        end

        opts.on('--version', 'Current gem version.') do |v|
          @options[:version] = v
        end
      end
    end
293179
def extract!( *list )
      list.each do |a|
        if a.is_a?(Hash)
          a.each { |t, o| adapter(t, o) }
        else
          adapter(a)
        end
      end
    end
322139
def options_hash_to_string(options)
      result = ''
      options.sort_by { |key, _| OPTION_ORDER.find_index(key) || -1 }.each do |key, value|
        if value
          result += "set #{OptionHandling.option_to_string(key, value)}\n"
        else
          result += "unset #{key}\n"
        end
      end
      result
    end
1246
private static OptionParser getParser() {
        OptionParser parser = new OptionParser();
        parser.accepts("help", "print help information");
        parser.accepts("url", "[REQUIRED] bootstrap URL")
              .withRequiredArg()
              .describedAs("bootstrap-url")
              .ofType(String.class);
        parser.accepts("in-dir",
                       "[REQUIRED] Directory in which to find the input key files (named \"{storeName}.kvs\", generated by KeyFetcherCLI.")
              .withRequiredArg()
              .describedAs("inputDirectory")
              .ofType(String.class);
        parser.accepts("out-dir",
                       "[REQUIRED] Directory in which to output the key files (named \"{storeName}.kvs\".")
              .withRequiredArg()
              .describedAs("outputDirectory")
              .ofType(String.class);
        parser.accepts("store-names",
                       "Store names to sample. Comma delimited list or singleton. [Default: ALL]")
              .withRequiredArg()
              .describedAs("storeNames")
              .withValuesSeparatedBy(',')
              .ofType(String.class);
        parser.accepts("parallelism",
                       "Number of key-versions to sample in parallel. [Default: "
                               + DEFAULT_KEY_PARALLELISM + " ]")
              .withRequiredArg()
              .describedAs("storeParallelism")
              .ofType(Integer.class);
        parser.accepts("progress-period-ops",
                       "Number of operations between progress info is displayed. [Default: "
                               + DEFAULT_PROGRESS_PERIOD_OPS + " ]")
              .withRequiredArg()
              .describedAs("progressPeriodOps")
              .ofType(Integer.class);
        parser.accepts("output-batch-size",
                       "Number of keys fetched and written out in sorted order at once. [Default: "
                               + DEFAULT_OUTPUT_BATCH_SIZE + " ]")
              .withRequiredArg()
              .describedAs("outputBatchSize")
              .ofType(Integer.class);
        parser.accepts("details",
                       "print details of each key-version: partition ID, node ID, & hostname");
        return parser;
    }
529442
def parse_args
      options = { :agent_name => 'instance', :verbose => false }

      parser = Trollop::Parser.new do
        opt :level, "", :type => String, :long => "--log-level", :short => "-l"
        opt :agent
        opt :verbose
        version ""
      end

      parse do
        options.merge!(parser.parse)
        if options[:level]
          fail("Invalid log level '#{options[:level]}'") unless AgentManager::LEVELS.include?(options[:level].to_sym)
        end
        options
      end
    end
386581
def parse_options_and_call_procs(*args)
      return args if args.empty?
      # empty proxy_options before populating via OptionParser
      # prevents duplication of options if the command is run twice
      proxy_options.clear
      @options.each_with_object(OptionParser.new) do |option, opts|
        opts.on(*option[:args], &option[:proc])
        opts
      end.parse! args
    end
1246571
def option_parser
      @option_parser ||= OptionParser.new(banner, 25) do |opts|
        opts.banner = banner

        OptionSetter.new(self, opts).setup
      end
    end
848064
def optparse(*args)
      opts = OptionParser.new

      opts.banner = "usage: #{$0} [options]"

      opts.on('-H','--host HOST',"The host to run the server on","Default: #{@host}") do |host|
        @host = host
      end

      opts.on('-p','--port PORT',"The port to run the server on","Default: #{@port}") do |port|
        @port = port.to_i
      end

      opts.on('--s','--server NAME','Rack handler to run the server under') do |handler|
        @handler = handler
      end

      opts.on('-h','--help','Display the help output') do
        puts opts
        exit
      end

      begin
        opts.parse!(args)
      rescue OptionParser::InvalidOption => e
        STDERR.puts e.message
        STDERR.puts opts
        exit -1
      end
    end
742951
def parse_args
      parser = Trollop::Parser.new do
        opt :action, "", :type => :string
        opt :boot, ""
      end

      parse do
        parser.parse
      end
    end
897901
def parse_args
      options = { :verbose => false, :status => false, :immediately => false, :action => :attach}

      parser = Trollop::Parser.new do 
        opt :url, "", :long => "--attach", :short => "-a", :type => String, :required => true
        opt :force
        opt :cloud, "", :type => String
        version ""
      end

      parse do
        options.merge(parser.parse)
      end
    end
838596
def option_parser
      @_option_parser ||= Slop.new do |command|
        command.banner "Usage: #{program_name} [options] [template_name]"

        command.on('-V', 'Shows version and exits') do
          print_and_exit Snp::VERSION
        end

        command.on('-h', 'Shows this message') do
          print_and_exit command.to_s
        end
      end
    end
391960
def parse_args
      options = {:reset => false}
      options[:agent_name] = ARGV[0] unless ARGV[0] =~ /^-/

      opts = OptionParser.new do |opts|
        parse_other_args(opts, options)

        opts.on('-r', '--reset') do
          options[:reset] = true
        end

        opts.on('-T', '--timeout SEC') do |sec|
          options[:timeout] = sec
        end

        opts.on('-j', '--json') do
          options[:json] = true
        end

        opts.on('-v', '--verbose') do
          options[:verbose] = true
        end

        opts.on("-c", "--cfg-dir DIR") do |d|
          options[:cfg_dir] = d
        end

        opts.on_tail('--help') do
          puts Usage.scan(__FILE__)
          exit
        end

      end

      begin
        opts.parse(ARGV)
      rescue Exception => e
        exit 0 if e.is_a?(SystemExit)
        fail(e.message + "\nUse 'rstat --help' for additional information")
      end

      options
    end
186185
private static OptionParser getParser() {
        OptionParser parser = new OptionParser();
        parser.accepts("help", "print help information");
        parser.accepts("url", "[REQUIRED] bootstrap URL")
              .withRequiredArg()
              .describedAs("bootstrap-url for the cluster in which a node is to be replaced")
              .ofType(String.class);
        parser.accepts("node", "[REQUIRED] node id.")
              .withRequiredArg()
              .describedAs("node id which needs to be replaced by the new node")
              .ofType(Integer.class);
        parser.accepts("newurl", "[REQUIRED] new bootstrap-url")
              .withRequiredArg()
              .describedAs("bootstrap-url for the new cluster, which will replace the node id")
              .ofType(String.class);
        parser.accepts("skip-restore", "do not restore data from existing machine");
        parser.accepts("parallelism", "parallel data restores.")
              .withRequiredArg()
              .describedAs("number of data restores to happen in parallel")
              .ofType(Integer.class)
              .defaultsTo(3);
        return parser;
    }
54144
def parse_options(parser_configuration = {})
      raise_on_invalid_option = parser_configuration.has_key?(:raise_on_invalid_option) ? parser_configuration[:raise_on_invalid_option] : true
      parse_base_options = parser_configuration.has_key?(:parse_base_options) ? parser_configuration[:parse_base_options] : true
      logger.debug "parsing args: #{@args.inspect}, raise_on_invalid_option: #{raise_on_invalid_option}, parse_base_options: #{parse_base_options}"

      @option_parser ||= OptionParser.new

      option_parser.banner = help + "\n\nOptions:"

      if parse_base_options
        option_parser.on("--template [NAME]", "Use a template to render output. (default=default.slim)") do |t|
          options[:template] = t.nil? ? "default.slim" : t
          @template = options[:template]
        end

        option_parser.on("--output FILENAME", "Render output directly to a file") do |f|
          options[:output] = f
          @output = options[:output]
        end

        option_parser.on("--force", "Overwrite file output without prompting") do |f|
          options[:force] = f
        end

        option_parser.on("-r", "--repos a1,a2,a3", "--asset a1,a2,a3", "--filter a1,a2,a3", Array, "List of regex asset name filters") do |list|
          options[:filter] = list
        end

        # NOTE: OptionParser will add short options, there is no way to stop '-m' from being the same as '--match'
        option_parser.on("--match [MODE]", "Asset filter match mode.  MODE=ALL (default), FIRST, EXACT, or ONE (fails if more than 1 match)") do |m|
          options[:match] = m || "ALL"
          options[:match].upcase!
          unless ["ALL", "FIRST", "EXACT", "ONE"].include?(options[:match])
            puts "invalid match mode option: #{options[:match]}"
            exit 1
          end
        end
      end

      # allow decendants to add options
      yield option_parser if block_given?

      # reprocess args for known options, see binary wrapper for first pass
      # (first pass doesn't know about action specific options), find all
      # action options that may come after the action/subcommand (options
      # before subcommand have already been processed) and its args
      logger.debug "args before reprocessing: #{@args.inspect}"
      begin
        option_parser.order!(@args)
      rescue OptionParser::InvalidOption => e
        if raise_on_invalid_option
          puts "option error: #{e}"
          puts option_parser
          exit 1
        else
          # parse and consume until we hit an unknown option (not arg), put it back so it
          # can be shifted into the new array
          e.recover(@args)
        end
      end
      logger.debug "args before unknown collection: #{@args.inspect}"

      unknown_args = []
      while unknown_arg = @args.shift
        logger.debug "unknown_arg: #{unknown_arg.inspect}"
        unknown_args << unknown_arg
        begin
          # consume options and stop at an arg
          option_parser.order!(@args)
        rescue OptionParser::InvalidOption => e
          if raise_on_invalid_option
            puts "option error: #{e}"
            puts option_parser
            exit 1
          else
            # parse and consume until we hit an unknown option (not arg), put it back so it
            # can be shifted into the new array
            e.recover(@args)
          end
        end
      end
      logger.debug "args after unknown collection: #{@args.inspect}"

      @args = unknown_args.dup
      logger.debug "args after reprocessing: #{@args.inspect}"
      logger.debug "configuration after reprocessing: #{@configuration.inspect}"
      logger.debug "options after reprocessing: #{@options.inspect}"

      option_parser
    end