Class: Gingerice::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gingerice/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



10
11
12
13
14
15
16
# File 'lib/gingerice/command.rb', line 10

def initialize(args)
  @args = args
  @args << '-h' if @args.empty?

  @options     = Gingerice::Parser.default_options.merge({ :output => :simple })
  @args_parser = parse_args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/gingerice/command.rb', line 8

def args
  @args
end

#args_parserObject (readonly)

Returns the value of attribute args_parser.



8
9
10
# File 'lib/gingerice/command.rb', line 8

def args_parser
  @args_parser
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/gingerice/command.rb', line 8

def options
  @options
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gingerice/command.rb', line 18

def execute
  if options.has_key?(:show)

    case options[:show]
    when :help
      puts args_parser
    when :version
      puts "Gingerice: #{Gingerice::VERSION}"
    end

  else
    parser_opts = options.select { |k, _| Parser.default_options.keys.include?(k) }
    parser      = Parser.new(parser_opts)
    response    = parser.parse(args.last)

    if options[:output] === :verbose
      ap response
    else
      puts response
    end
  end
end