Class: MrMurano::SubCmdGroupHelp

Inherits:
Object
  • Object
show all
Defined in:
lib/MrMurano/SubCmdGroupContext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ SubCmdGroupHelp

Returns a new instance of SubCmdGroupHelp.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 6

def initialize(command)
  @name = command.syntax.to_s
  @description = command.description.to_s
  @runner = ::Commander::Runner.instance
  prefix = /^#{command.name.to_s} /
  cmds = @runner.instance_variable_get(:@commands).select{|n,_| n.to_s =~ prefix}
  @commands = cmds
  als = @runner.instance_variable_get(:@aliases).select{|n,_| n.to_s =~ prefix}
  @aliases = als

  @options = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 4

def name
  @name
end

Instance Method Details

#alias?(name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 32

def alias?(name)
  @aliases.include? name.to_s
end

#command(name) ⇒ Object



36
37
38
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 36

def command(name)
  @commands[name.to_s]
end

#get_helpObject



40
41
42
43
44
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 40

def get_help
  hf = @runner.program(:help_formatter).new(self)
  pc = Commander::HelpFormatter::ProgramContext.new(self).get_binding
  hf.template(:help).result(pc)
end

#program(key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 19

def program(key)
  case key
  when :name
    @name
  when :description
    @description
  when :help
    nil
  else
    nil
  end
end