Class: Rubydex::CLI::Command
- Inherits:
-
Object
- Object
- Rubydex::CLI::Command
- Defined in:
- lib/rubydex/cli/command.rb,
lib/rubydex/cli/command/mcp.rb,
lib/rubydex/cli/command/lint.rb,
lib/rubydex/cli/command/query.rb,
lib/rubydex/cli/command/skill.rb,
lib/rubydex/cli/command/console.rb,
lib/rubydex/cli/command/lint/explain.rb
Overview
rdx console — opens an IRB session with a populated graph for the current workspace.
Direct Known Subclasses
Defined Under Namespace
Classes: Console, Lint, Mcp, Query, Skill
Class Attribute Summary collapse
-
.command_name ⇒ Object
readonly
The subcommand name declared by Command.command.
Class Method Summary collapse
-
.all ⇒ Object
Every subcommand, in alphabetical order.
-
.arguments(spec = nil) ⇒ Object
Declares the argument spec shown after the command name in
rdx help, e.g. -
.command(value) ⇒ Object
Declares the subcommand name this class is dispatched under.
-
.declared ⇒ Object
The subcommands that are currently loaded, in alphabetical order.
-
.find(name) ⇒ Object
The subcommand declared under
name, if any. -
.summary(text = nil) ⇒ Object
Declares the description shown in
rdx help. -
.usage_form ⇒ Object
How the command is spelled in a usage line, e.g.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Command
constructor
: (Array argv) -> void.
-
#run ⇒ Object
: -> void.
Constructor Details
Class Attribute Details
.command_name ⇒ Object (readonly)
The subcommand name declared by command. nil for a class that declares none, which is
how an abstract intermediate class opts out of being dispatched.
: String?
27 28 29 |
# File 'lib/rubydex/cli/command.rb', line 27 def command_name @command_name end |
Class Method Details
.all ⇒ Object
Every subcommand, in alphabetical order. Loads the command files first, so the answer does not depend on what happens to have been required already. : -> Array
79 80 81 82 83 |
# File 'lib/rubydex/cli/command.rb', line 79 def all Dir.glob(File.("command/*.rb", __dir__)).sort.each { |file| require(file) } declared end |
.arguments(spec = nil) ⇒ Object
Declares the argument spec shown after the command name in rdx help, e.g. "<CYPHER>".
Called without an argument, returns the declared spec.
: (?String? spec) -> String?
47 48 49 50 51 |
# File 'lib/rubydex/cli/command.rb', line 47 def arguments(spec = nil) return @arguments unless spec @arguments = spec #: String? end |
.command(value) ⇒ Object
Declares the subcommand name this class is dispatched under.
Deliberately not called name: that would shadow Class#name, which Ruby uses when it
builds error messages, so a NoMethodError on a command would report "an instance of
query" instead of naming the class.
: (String value) -> void
35 36 37 38 39 40 41 42 |
# File 'lib/rubydex/cli/command.rb', line 35 def command(value) # Deliberately checked against {.declared} rather than {.find}: this runs while a command # file is still being loaded, and `find` would glob in every other command file first. clash = declared.find { |other| !other.equal?(self) && other.command_name == value } raise ArgumentError, "command `#{value}` is already declared by #{clash}" if clash @command_name = value #: String? end |
.declared ⇒ Object
The subcommands that are currently loaded, in alphabetical order. Loads nothing itself, so it is safe to call while a command file is still being evaluated. : -> Array
72 73 74 |
# File 'lib/rubydex/cli/command.rb', line 72 def declared Command.subclasses.select(&:command_name).sort_by(&:command_name) end |
.find(name) ⇒ Object
The subcommand declared under name, if any.
: (String? name) -> singleton(Command)?
87 88 89 |
# File 'lib/rubydex/cli/command.rb', line 87 def find(name) all.find { |command| command.command_name == name } end |
.summary(text = nil) ⇒ Object
Declares the description shown in rdx help. May span several lines, which are aligned
under the first when the command list is rendered. Called without an argument, returns the
declared description.
: (?String? text) -> String?
57 58 59 60 61 |
# File 'lib/rubydex/cli/command.rb', line 57 def summary(text = nil) return @summary unless text @summary = text.strip #: String? end |
.usage_form ⇒ Object
How the command is spelled in a usage line, e.g. "query <CYPHER>".
: -> String
65 66 67 |
# File 'lib/rubydex/cli/command.rb', line 65 def usage_form [command_name, arguments].compact.join(" ") end |
Instance Method Details
#run ⇒ Object
: -> void
98 99 100 |
# File 'lib/rubydex/cli/command.rb', line 98 def run raise NotImplementedError, "#{self.class} must implement #run" end |