Module: CLI::Kit::CommandHelp

Extended by:
T::Sig
Includes:
Kernel
Included in:
BaseCommand
Defined in:
lib/cli/kit/command_help.rb

Defined Under Namespace

Modules: ClassMethods

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from T::Sig

sig

Class Attribute Details

.max_desc_length=(value) ⇒ Object (writeonly)

Sets the attribute max_desc_length

Parameters:

  • value

    the value to set the attribute max_desc_length to.



56
57
58
# File 'lib/cli/kit/command_help.rb', line 56

def max_desc_length=(value)
  @max_desc_length = value
end

.tool_name=(value) ⇒ Object (writeonly)

Sets the attribute tool_name

Parameters:

  • value

    the value to set the attribute tool_name to.



53
54
55
# File 'lib/cli/kit/command_help.rb', line 53

def tool_name=(value)
  @tool_name = value
end

Class Method Details

._max_desc_lengthObject



68
69
70
# File 'lib/cli/kit/command_help.rb', line 68

def _max_desc_length
  @max_desc_length || 80
end

._tool_nameObject



59
60
61
62
63
64
65
# File 'lib/cli/kit/command_help.rb', line 59

def _tool_name
  unless @tool_name
    raise 'You must set CLI::Kit::CommandHelp.tool_name='
  end

  @tool_name
end

Instance Method Details

#call(args, name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cli/kit/command_help.rb', line 12

def call(args, name)
  begin
    opts = self.class.opts_class
    opts_inst = opts.new
    defn = Args::Definition.new
    opts_inst.define!(defn)
    tokens = Args::Tokenizer.tokenize(args)
    parse = Args::Parser.new(defn).parse(tokens)
    evl = Args::Evaluation.new(defn, parse)
    opts_inst.evaluate!(evl)
  rescue Args::Evaluation::TooManyPositions, Args::Evaluation::MissingRequiredPosition => e
    STDERR.puts CLI::UI.fmt("{{red:{{bold:Error: #{e.message}}}}}")
    STDERR.puts
    STDERR.puts self.class.build_help
    raise(AbortSilent)
  rescue Args::Error => e
    raise(Abort, e)
  end

  if opts_inst.helpflag
    puts self.class.build_help
  else
    invoke_wrapper(opts_inst, name)
  end
end

#invoke(op, name) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/cli/kit/command_help.rb', line 45

def invoke(op, name)
  raise(NotImplementedError, '#invoke must be implemented, or #call overridden')
end

#invoke_wrapper(op, name) ⇒ Object



40
41
42
# File 'lib/cli/kit/command_help.rb', line 40

def invoke_wrapper(op, name)
  invoke(op, name)
end