Takes the diff command line output (as Array) and parse it into a Hash

 @param [String] diff_command the diff commadn to be used
 @param [Array] opts the diff options to be used
 @return [Hash] the diff as Hash
19310
def diff_as_hash(diff_command, opts=[])
      command_lines(diff_command, opts).inject({}) do |memo, line|
        info, file = line.split("\t")
        mode_src, mode_dest, sha_src, sha_dest, type = info.split

        memo[file] = {
          :mode_index => mode_dest,
          :mode_repo => mode_src.to_s[1, 7],
          :path => file,
          :sha_repo => sha_src,
          :sha_index => sha_dest,
          :type => type
        }

        memo
      end
    end
1351165
def combine_diffs(diff_one, diff_two)
      Hash.new { |hash, key| hash[key] = [[], []] }.tap do |combined_diff|
        diff_one.each do |change|
          combined_diff[change.old_position].first << change
        end

        diff_two.each do |change|
          combined_diff[change.old_position].last << change
        end
      end
    end
381698
def by_hash_ids(*args)
      cmd_options = args.last.kind_of?(Hash) ? args.last : {}
      
      if args.size == 1 && args.first.kind_of?(Array)
        array = args.first
      else
        array = args
      end      
      return [] if array.empty?

      args = array.map{|hash| " -r#{ hash }"}
      hg_to_array ["log#{ args.join('') } --style ?", style], {:separator => changeset_separator}, cmd_options do |line|
        build(line)
      end
    end
435181
def grep(string, opts = {})
      opts[:object] ||= 'HEAD'

      grep_opts = ['-n']
      grep_opts << '-i' if opts[:ignore_case]
      grep_opts << '-v' if opts[:invert_match]
      grep_opts << '-e'
      grep_opts << string
      grep_opts << opts[:object] if opts[:object].is_a?(String)
      grep_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String

      hsh = {}
      command_lines('grep', grep_opts).each do |line|
        if m = /(.*)\:(\d+)\:(.*)/.match(line)
          hsh[m[1]] ||= []
          hsh[m[1]] << [m[2].to_i, m[3]]
        end
      end
      hsh
    end
753178
def generate(options, command: nil)
      # First, enable `always_trace`, to show the stack trace
      always_trace!

      used_switches = []
      options.each do |option|
        next if option.description.to_s.empty? # "private" options
        next unless option.display_in_shell

        short_switch = option.short_option
        key = option.key
        validate_short_switch(used_switches, short_switch, key)

        type = option.data_type

        # We added type: Hash to code generation, but Ruby's OptionParser doesn't like that
        # so we need to switch that to something that is supported, luckily, we have an `is_string`
        # property and if that is false, we'll default to nil
        if type == Hash
          type = option.is_string ? String : nil
        end

        # Boolean is a fastlane thing, it's either TrueClass, or FalseClass, but we won't know
        # that until runtime, so nil is the best we get
        if type == Fastlane::Boolean
          type = nil
        end

        # This is an important bit of trickery to solve the boolean option situation.
        #
        # Typically, boolean command line flags do not accept trailing values. If the flag
        # is present, the value is true, if it is missing, the value is false. fastlane
        # supports this style of flag. For example, you can specify a flag like `--clean`,
        # and the :clean option will be true.
        #
        # However, fastlane also supports another boolean flag style that accepts trailing
        # values much like options for Strings and other value types. That looks like
        # `--include_bitcode false` The problem is that this does not work out of the box
        # for Commander and OptionsParser. So, we need to get tricky.
        #
        # The value_appendix below acts as a placeholder in the switch definition that
        # states that we expect to have a trailing value for our options. When an option
        # declares a data type, we use the name of that data type in all caps like:
        # "--devices ARRAY". When the data type is nil, this implies that we're going
        # to be doing some special handling on that value. One special thing we do
        # automatically in Configuration is to coerce special Strings into boolean values.
        #
        # If the data type is nil, the trick we do is to specify a value placeholder, but
        # we wrap it in [] brackets to mark it as optional. That means that the trailing
        # value may or may not be present for this flag. If the flag is present, but the
        # value is not, we get a value of `true`. Perfect for the boolean flag base-case!
        # If the value is there, we'll actually get it back as a String, which we can
        # later coerce into a boolean.
        #
        # In this way we support handling boolean flags with or without trailing values.
        value_appendix = (type || '[VALUE]').to_s.upcase
        long_switch = "--#{option.key} #{value_appendix}"

        description = option.description
        description += " (#{option.env_name})" unless option.env_name.to_s.empty?

        # We compact this array here to remove the short_switch variable if it is nil.
        # Passing a nil value to global_option has been shown to create problems with
        # option parsing!
        #
        # See: https://github.com/fastlane/fastlane_core/pull/89
        #
        # If we don't have a data type for this option, we tell it to act like a String.
        # This allows us to get a reasonable value for boolean options that can be
        # automatically coerced or otherwise handled by the ConfigItem for others.
        args = [short_switch, long_switch, (type || String), description].compact

        if command
          command.option(*args)
        else
          # This is the call to Commander to set up the option we've been building.
          global_option(*args)
        end
      end
    end
228971
def stats_command(opts)
      CommandIO.instance.reply(opts[:conn], JSON.dump(@agent_manager.stats({:reset => opts[:reset]})))
    end
594019
def common_options(opts, options)
      opts.separator ''
      opts.separator 'Common options:'
      # Another typical switch to print the version.
      opts.on('-v', '--version', 'Show version') do
        PRINTER.print Sshez.version
        options.halt = true
      end
      opts.on('-z', '--verbose', 'Verbose Output') do
        PRINTER.verbose!
      end
      # Prints everything
      opts.on_tail('-h', '--help', 'Show this message') do
        PRINTER.print opts
        options.halt = true
      end
    end
994736
def parse_cli_options!(args)
      unknown_opts = []

      parser = build_cli_parser

      begin
        parser.parse!(args)
      rescue OptionParser::InvalidOption => e
        unknown_opts << e.args[0]
        unless args.size.zero?
          unknown_opts << args.shift unless args.first.start_with?("-")
          retry
        end
      end

      unknown_opts
    end
1337344
def array_diff(array1, array2, format = :text)
    string1 = array1.join("\n") + "\n"
    string2 = array2.join("\n") + "\n"
    Diffy::Diff.new(string1, string2).to_s(format)
  end
1128537
def parse_options!(args)
			@options = {}
			opts = ::OptionParser.new do |opts|
				opts.banner = "Usage: syswatch [options]\n\n  Options:"

				opts.on("-f", "--foreground", "Do not daemonize, just run in foreground.") do |f|
					@options[:foreground] = f
				end

				opts.on("-v", "--verbose", "Be verbose, print out some messages.") do |v|
					@options[:verbose] = v
				end

				opts.on("-t", "--test", "Test notifications.") do |t|
					@options[:test] = t
				end

				opts.on("-c", "--config [FILE]", "Use a specific config file, instead of `#{SysWatch::DEFAULTS[:config]}`") do |config|
					@options[:config] = config
				end
			end
			opts.parse! args
		end
958259
function parseOptions(opts) {
  opts = opts || {};
  var argv = [];
  var options = {};
  var process_argv = process.argv;
  for (var i = 2; i < process_argv.length; i++) {
    if (process_argv[i].indexOf('--') == 0) {
      var arg = process_argv[i];
      if (arg.indexOf("=") > 0) {
        var arg_kv = arg.split('=');
        arg = arg_kv[0];
        arg = arg.replace('--','');
        arg = replaceAll(arg, '-', '_');
        options[arg] = arg_kv[1];
        if (typeof opts[arg] == 'string') {
          if (opts[arg] == 'int' || opts[arg] == 'integer') {
            options[arg] = parseInt(options[arg]);
          } else if (opts[arg] == 'float') {
            options[arg] = parseFloat(options[arg]);
          }
        } else if (typeof opts[arg] == 'object') {
          if (opts[arg].type == 'array') {
            var sep = opts[arg].separator || opts[arg].sep || ',';
            options[arg] = options[arg].split(sep);
          }
        }
      } else {
        arg = arg.replace('--','');
        arg = replaceAll(arg, '-', '_');
        options[arg] = true;
      }
    } else {
      argv.push(process_argv[i]);
    }
  }
  options.argv = argv;
  return options;
}
1319509
def list_command(opts)
      usage = "Agent exposes the following commands:\n"
      COMMANDS.reject { |k, _| k == :list || k.to_s =~ /test/ }.each do |c|
        c.each { |k, v| usage += " - #{k.to_s}: #{v}\n" }
      end
      CommandIO.instance.reply(opts[:conn], usage)
    end
94969
def process_args
      args = @args.dup
      @options[:operands] = nil
      unless args.length >= 2
        puts @opts
        exit 1
      end
      @options[:operands] = args.shift(2)
      @options[:output_filename] = args.shift unless args.empty?
      @options[:output] ||= @options[:output_filename] || $stdout

      run
    end
77668
def with_options(opts = {}) # :nodoc:
      opts = opts.dup
      opts.delete(:comment)
      @opt_stack.push( @opt_stack.last.merge(opts))
      yield self
      @opt_stack.pop
    end
800122
function MnListDiffMessage(arg, options) {
  Message.call(this, options);
  this.MnListDiff = options.MnListDiff;
  this.command = 'mnlistdiff';
  $.checkArgument(
    _.isUndefined(arg) || arg instanceof this.MnListDiff,
    'An instance of MnListDiff or undefined is expected'
  );
  this.mnlistdiff = arg;
}
953689
def rehash_options(opts)

      opts['Accept'] ||= (opts.delete(:accept) || 'application/json')
      opts['Accept'] = 'application/json' if opts['Accept'] == :json

      if ct = opts.delete(:content_type)
        opts['Content-Type'] = ct
      end
      if opts['Content-Type'] == :json
        opts['Content-Type'] = 'application/json'
      end

      if et = opts.delete(:etag)
        opts['If-None-Match'] = et
      end

      opts
    end
328991
def extract_options(args)
      options = args.last
      options.respond_to?(:to_hash) ? options.to_hash.dup : {}
    end