Class: Cl::Help::Usage

Inherits:
Struct
  • Object
show all
Defined in:
lib/cl/help/usage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd



3
4
5
# File 'lib/cl/help/usage.rb', line 3

def cmd
  @cmd
end

#ctxObject

Returns the value of attribute ctx

Returns:

  • (Object)

    the current value of ctx



3
4
5
# File 'lib/cl/help/usage.rb', line 3

def ctx
  @ctx
end

Instance Method Details

#executableObject



17
18
19
# File 'lib/cl/help/usage.rb', line 17

def executable
  ctx.name
end

#formatObject



4
5
6
7
8
# File 'lib/cl/help/usage.rb', line 4

def format
  cmd.registry_keys.map do |key|
    line(key)
  end
end

#line(key) ⇒ Object



10
11
12
13
14
15
# File 'lib/cl/help/usage.rb', line 10

def line(key)
  usage = [executable, key.to_s.gsub(':', ' ')]
  usage += cmd.args.map(&:to_s) # { |arg| "[#{arg}]" }
  usage << '[options]' if opts?
  usage.join(' ')
end

#opts?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cl/help/usage.rb', line 21

def opts?
  cmd.opts.any?
end