Class: Cl::Cmd
- Inherits:
-
Object
- Object
- Cl::Cmd
- Extended by:
- Dsl, Merge, Suggest, Underscore
- Includes:
- Registry
- Defined in:
- lib/cl/cmd.rb,
lib/cl/dsl.rb
Overview
Direct Known Subclasses
Defined Under Namespace
Modules: Dsl
Constant Summary
Constants included from Merge
Class Attribute Summary collapse
-
.auto_register ⇒ Object
Returns the value of attribute auto_register.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
Class Method Summary collapse
Instance Method Summary collapse
- #deprecations ⇒ Object
-
#initialize(ctx, args) ⇒ Cmd
constructor
A new instance of Cmd.
- #opts ⇒ Object
Methods included from Merge
Methods included from Suggest
Methods included from Underscore
Methods included from Dsl
abstract, abstract?, arg, description, examples, opt, required, required?, summary
Constructor Details
#initialize(ctx, args) ⇒ Cmd
Returns a new instance of Cmd.
59 60 61 62 63 64 |
# File 'lib/cl/cmd.rb', line 59 def initialize(ctx, args) @ctx = ctx args, opts = self.class.parse(ctx, self, args) @opts = self.class.opts.apply(self, self.opts.merge(opts)) @args = self.class.args.apply(self, args, opts) unless help? && !is_a?(Help) end |
Class Attribute Details
.auto_register ⇒ Object
Returns the value of attribute auto_register.
23 24 25 |
# File 'lib/cl/cmd.rb', line 23 def auto_register @auto_register end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
57 58 59 |
# File 'lib/cl/cmd.rb', line 57 def args @args end |
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
57 58 59 |
# File 'lib/cl/cmd.rb', line 57 def ctx @ctx end |
Class Method Details
.cmds ⇒ Object
35 36 37 |
# File 'lib/cl/cmd.rb', line 35 def cmds registry.values.uniq end |
.parse(ctx, cmd, args) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/cl/cmd.rb', line 39 def parse(ctx, cmd, args) parser = Parser.new(cmd, args) args, opts = parser.args, parser.opts unless self == Help opts = merge(ctx.config[registry_key], opts) if ctx.config[registry_key] [args, opts || {}] end |
.suggestions(opt) ⇒ Object
46 47 48 |
# File 'lib/cl/cmd.rb', line 46 def suggestions(opt) suggest(opts.map(&:name), opt.sub(/^--/, '')) end |
Instance Method Details
#deprecations ⇒ Object
70 71 72 |
# File 'lib/cl/cmd.rb', line 70 def deprecations @deprecations ||= {} end |
#opts ⇒ Object
66 67 68 |
# File 'lib/cl/cmd.rb', line 66 def opts @opts ||= {} end |