Module: CLI::Kit::CommandHelp
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.max_desc_length ⇒ Object
writeonly
: Integer.
-
.tool_name ⇒ Object
writeonly
: String.
Class Method Summary collapse
-
._max_desc_length ⇒ Object
: -> Integer.
-
._tool_name ⇒ Object
: -> String.
Instance Method Summary collapse
-
#call(args, name) ⇒ Object
: (Array args, String name) -> void.
-
#invoke(op, name) ⇒ Object
: (untyped op, String name) -> void.
-
#invoke_wrapper(op, name) ⇒ Object
use to implement error handling : (untyped op, String name) -> void.
Class Attribute Details
.max_desc_length=(value) ⇒ Object (writeonly)
: Integer
53 54 55 |
# File 'lib/cli/kit/command_help.rb', line 53 def max_desc_length=(value) @max_desc_length = value end |
.tool_name=(value) ⇒ Object (writeonly)
: String
50 51 52 |
# File 'lib/cli/kit/command_help.rb', line 50 def tool_name=(value) @tool_name = value end |
Class Method Details
._max_desc_length ⇒ Object
: -> Integer
65 66 67 |
# File 'lib/cli/kit/command_help.rb', line 65 def _max_desc_length @max_desc_length || 80 end |
._tool_name ⇒ Object
: -> String
56 57 58 59 60 61 62 |
# File 'lib/cli/kit/command_help.rb', line 56 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
: (Array args, String name) -> void
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cli/kit/command_help.rb', line 11 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
: (untyped op, String name) -> void
44 45 46 |
# File 'lib/cli/kit/command_help.rb', line 44 def invoke(op, name) raise(NotImplementedError, '#invoke must be implemented, or #call overridden') end |
#invoke_wrapper(op, name) ⇒ Object
use to implement error handling : (untyped op, String name) -> void
39 40 41 |
# File 'lib/cli/kit/command_help.rb', line 39 def invoke_wrapper(op, name) invoke(op, name) end |