Class: Textus::Surfaces::CLI::Group
- Defined in:
- lib/textus/surfaces/cli/group.rb,
lib/textus/surfaces/cli/group/key.rb,
lib/textus/surfaces/cli/group/mcp.rb,
lib/textus/surfaces/cli/group/data.rb,
lib/textus/surfaces/cli/group/rule.rb,
lib/textus/surfaces/cli/group/schema.rb
Defined Under Namespace
Classes: Data, Key, MCP, 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, descendants, #emit, #gate_dispatch, inherited, #initialize, option, options, parent_group, #resolved_role
Constructor Details
This class inherits a constructor from Textus::Surfaces::CLI::Verb
Class Method Details
.needs_store? ⇒ Boolean
17 18 19 20 |
# File 'lib/textus/surfaces/cli/group.rb', line 17 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.
9 10 11 12 13 14 15 |
# File 'lib/textus/surfaces/cli/group.rb', line 9 def subcommands Textus::Surfaces::CLI::Runner.install! 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
44 45 46 |
# File 'lib/textus/surfaces/cli/group.rb', line 44 def call(store) @sub.call(@sub_klass.needs_store? ? store : nil) end |
#parse(argv) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/textus/surfaces/cli/group.rb', line 23 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 |