src/redis-trib.rb
def parse_options(cmd)
        idx = 1 ; # Current index into ARGV
        options={}
        while idx < ARGV.length && ARGV[idx][0..1] == '--'
            if ARGV[idx][0..1] == "--"
                option = ARGV[idx][2..-1]
                idx += 1
                if ALLOWED_OPTIONS[cmd] == nil || ALLOWED_OPTIONS[cmd][option] == nil
                    puts "Unknown option '#{option}' for command '#{cmd}'"
                    exit 1
                end
                if ALLOWED_OPTIONS[cmd][option]
                    value = ARGV[idx]
                    idx += 1
                else
                    value = true
                end
                options[option] = value
            else
                # Remaining arguments are not options.
                break
            end
        end
        return options,idx
    end
# Parse the options for the specific command "cmd".
# Returns an hash populate with option => value pairs, and the index of
# the first non-option argument in ARGV.
Parse the options for the specific command "cmd".
Returns an hash populate with option => value pairs, and the index of
the first non-option argument in ARGV.
Parse the options for the specific command " cmd " . Returns an hash populate with option = > value pairs and the index of the first non - option argument in ARGV .
def parse_options(cmd)
        idx = 1 ; 
        options={}
        while idx < ARGV.length && ARGV[idx][0..1] == '--'
            if ARGV[idx][0..1] == "--"
                option = ARGV[idx][2..-1]
                idx += 1
                if ALLOWED_OPTIONS[cmd] == nil || ALLOWED_OPTIONS[cmd][option] == nil
                    puts "Unknown option '#{option}' for command '#{cmd}'"
                    exit 1
                end
                if ALLOWED_OPTIONS[cmd][option]
                    value = ARGV[idx]
                    idx += 1
                else
                    value = true
                end
                options[option] = value
            else
                break
            end
        end
        return options,idx
    end
def parse_options ( cmd ) idx = 1 ; options = { } while idx < ARGV . length && ARGV [ idx ] [ 0 .. 1 ] == '--' if ARGV [ idx ] [ 0 .. 1 ] == "--" option = ARGV [ idx ] [ 2 .. - 1 ] idx += 1 if ALLOWED_OPTIONS [ cmd ] == nil || ALLOWED_OPTIONS [ cmd ] [ option ] == nil puts "Unknown option '#{option}' for command '#{cmd}'" exit 1 end if ALLOWED_OPTIONS [ cmd ] [ option ] value = ARGV [ idx ] idx += 1 else value = true end options [ option ] = value else break end end return options , idx end
Parse the options for the specific command "cmd".
Parse the options for the specific command " cmd " .
# Current index into ARGV # Remaining arguments are not options.
cmd