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
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.
54 55 56 57 58 59 |
# File 'lib/cl/cmd.rb', line 54 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) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
52 53 54 |
# File 'lib/cl/cmd.rb', line 52 def args @args end |
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
52 53 54 |
# File 'lib/cl/cmd.rb', line 52 def ctx @ctx end |
Class Method Details
.cmds ⇒ Object
32 33 34 |
# File 'lib/cl/cmd.rb', line 32 def cmds registry.values end |
.parse(ctx, cmd, args) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cl/cmd.rb', line 36 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
43 44 45 |
# File 'lib/cl/cmd.rb', line 43 def suggestions(opt) suggest(opts.map(&:name), opt.sub(/^--/, '')) end |
Instance Method Details
#deprecations ⇒ Object
65 66 67 |
# File 'lib/cl/cmd.rb', line 65 def deprecations @deprecations ||= {} end |
#opts ⇒ Object
61 62 63 |
# File 'lib/cl/cmd.rb', line 61 def opts @opts ||= {} end |