Class: Textus::CLI::Group
- Defined in:
- lib/textus/cli/group.rb,
lib/textus/cli/group/key.rb,
lib/textus/cli/group/hook.rb,
lib/textus/cli/group/rule.rb,
lib/textus/cli/group/schema.rb,
lib/textus/cli/group/refresh.rb
Defined Under Namespace
Classes: Hook, Key, Refresh, Rule, Schema
Instance Attribute Summary
Attributes inherited from Verb
Class Method Summary collapse
- .needs_store? ⇒ Boolean
-
.subcommands ⇒ Object
Subcommands are auto-derived: any Verb descendant whose ‘parent_group` is this group counts as a subcommand.
Instance Method Summary collapse
Methods inherited from Verb
command_name, #context_for, descendants, #emit, inherited, #initialize, #operations_for, option, options, parent_group, #resolved_role
Constructor Details
This class inherits a constructor from Textus::CLI::Verb
Class Method Details
.needs_store? ⇒ Boolean
15 16 17 18 |
# File 'lib/textus/cli/group.rb', line 15 def needs_store? # Delegate to the matched subcommand at parse time; default true. true end |
.subcommands ⇒ Object
Subcommands are auto-derived: any Verb descendant whose ‘parent_group` is this group counts as a subcommand. Sorted alphabetically by command_name for stable help output.
8 9 10 11 12 13 |
# File 'lib/textus/cli/group.rb', line 8 def subcommands Verb.descendants .select { |k| k.parent_group == self && k.command_name } .sort_by(&:command_name) .to_h { |k| [k.command_name, k] } end |
Instance Method Details
#call(store) ⇒ Object
42 43 44 |
# File 'lib/textus/cli/group.rb', line 42 def call(store) @sub.call(@sub_klass.needs_store? ? store : nil) end |
#parse(argv) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/textus/cli/group.rb', line 21 def parse(argv) subs = self.class.subcommands subname = argv.shift if subname.nil? raise UsageError.new( "#{self.class.command_name} requires a subcommand: #{subs.keys.join(", ")}", ) end @sub_klass = subs[subname] unless @sub_klass raise UsageError.new( "unknown #{self.class.command_name} subcommand '#{subname}'. " \ "Valid: #{subs.keys.join(", ")}", ) end @sub = @sub_klass.new(stdin: @stdin, stdout: @stdout, stderr: @stderr, cwd: @cwd) @sub.parse(argv) end |