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.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 13

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

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 10

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 11

def name
  @name
end

Instance Method Details

#alias?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#command(name) ⇒ Object



45
46
47
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 45

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

#get_helpObject

rubocop:disable Style/AccessorMethodName “Do not prefix reader method names with get_.”



51
52
53
54
55
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 51

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/MrMurano/SubCmdGroupContext.rb', line 26

def program(key)
  case key
  when :name
    @name
  when :description
    @description
  when :help
    nil
  # rubocop:disable Style/EmptyElse: "Redundant else-clause."
  # Rubocop seems incorrect about this one.
  else
    nil
  end
end