Class: Shoes::UI::CLI::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
shoes-core/lib/shoes/ui/cli/base_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BaseCommand

Returns a new instance of BaseCommand.



9
10
11
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 9

def initialize(*args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 7

def args
  @args
end

Instance Method Details

#helpObject



31
32
33
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 31

def help
  nil
end

#help_from_options(command, options) ⇒ Object



35
36
37
38
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 35

def help_from_options(command, options)
  lines = ["#{command}\n"] + options.summarize
  lines.join("")
end

#parse!(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 20

def parse!(args)
  options.parse!(args)
  true
rescue OptionParser::InvalidOption => e
  puts "Whoops! #{e.message}"
  puts
  puts help

  false
end

#warn_on_unexpected_parameters(expected_size = 1) ⇒ Object



13
14
15
16
17
18
# File 'shoes-core/lib/shoes/ui/cli/base_command.rb', line 13

def warn_on_unexpected_parameters(expected_size = 1)
  return unless args.size > expected_size

  unexpected = args[expected_size..-1].join(" ")
  Shoes.logger.warn("Unexpected extra parameters '#{unexpected}'")
end