Class: CommandLineUtils::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/command-line-utils/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommands

Returns a new instance of Commands.



9
10
11
12
13
14
# File 'lib/command-line-utils/commands.rb', line 9

def initialize
  @commands = ["help"]
  @help = false
  @summery = ""
  @banner = ""
end

Instance Attribute Details

#command_optionsObject

Returns the value of attribute command_options.



8
9
10
# File 'lib/command-line-utils/commands.rb', line 8

def command_options
  @command_options
end

#commandsObject (readonly)

Returns the value of attribute commands.



7
8
9
# File 'lib/command-line-utils/commands.rb', line 7

def commands
  @commands
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/command-line-utils/commands.rb', line 8

def options
  @options
end

Instance Method Details

#helpObject

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/command-line-utils/commands.rb', line 16

def help
  opt = OptionParser.new
  opt.parse!(@command_options)
  @summery = "Show command helps."
  @banner = "command"
  return opt if @help

  @help = true
  command = @command_options.shift
  raise UsageException unless command
  raise "Unknown command: " + command unless commands.include?(command)
  opt = send(command.gsub(/:/,"_"))
  puts "Summery: #{@summery}"
  opt.banner += " #{command} #{@banner}" if opt
  puts opt if opt
end