Class: FluidCLI::Command
- Inherits:
-
CLI::Kit::BaseCommand
- Object
- CLI::Kit::BaseCommand
- FluidCLI::Command
- Defined in:
- lib/fluid_cli/command.rb
Direct Known Subclasses
FluidCLI::Commands::Help, FluidCLI::Commands::Login, FluidCLI::Commands::Logout, FluidCLI::Commands::Switch, FluidCLI::Commands::Theme, FluidCLI::Commands::Theme::Dev, FluidCLI::Commands::Theme::Init, FluidCLI::Commands::Theme::Navigate, FluidCLI::Commands::Theme::Pull, FluidCLI::Commands::Theme::Push, FluidCLI::Commands::Whoami
Class Attribute Summary collapse
-
.ctx ⇒ Object
writeonly
Sets the attribute ctx.
Instance Attribute Summary collapse
-
#ctx ⇒ Object
writeonly
Sets the attribute ctx.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .call(args, command_name) ⇒ Object
- .call_help(*cmds) ⇒ Object
- .options(&block) ⇒ Object
- .subcommand(const, cmd, path = nil) ⇒ Object
- .subcommand_registry ⇒ Object
Instance Method Summary collapse
-
#initialize(ctx = nil) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(ctx = nil) ⇒ Command
Returns a new instance of Command.
49 50 51 52 53 |
# File 'lib/fluid_cli/command.rb', line 49 def initialize(ctx = nil) super() @ctx = ctx || FluidCLI::Context.new self. = Options.new end |
Class Attribute Details
.ctx=(value) ⇒ Object (writeonly)
Sets the attribute ctx
10 11 12 |
# File 'lib/fluid_cli/command.rb', line 10 def ctx=(value) @ctx = value end |
Instance Attribute Details
#ctx=(value) ⇒ Object (writeonly)
Sets the attribute ctx
6 7 8 |
# File 'lib/fluid_cli/command.rb', line 6 def ctx=(value) @ctx = value end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/fluid_cli/command.rb', line 7 def end |
Class Method Details
.call(args, command_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fluid_cli/command.rb', line 12 def call(args, command_name, *) subcommand, resolved_name = subcommand_registry.lookup_command(args.first) if subcommand subcommand.ctx = @ctx subcommand.call(args.drop(1), resolved_name, command_name) else cmd = new(@ctx) cmd..parse(, args) cmd.call(args, command_name) end end |
.call_help(*cmds) ⇒ Object
43 44 45 46 |
# File 'lib/fluid_cli/command.rb', line 43 def call_help(*cmds) help = Commands::Help.new(@ctx) help.call(cmds, nil) end |
.options(&block) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/fluid_cli/command.rb', line 24 def (&block) = # We prevent new options calls to override existing blocks by nesting them. = ->(parser, flags) { &.call(parser, flags) block.call(parser, flags) } end |
.subcommand(const, cmd, path = nil) ⇒ Object
33 34 35 36 |
# File 'lib/fluid_cli/command.rb', line 33 def subcommand(const, cmd, path = nil) autoload(const, path) if path subcommand_registry.add(->() { const_get(const) }, cmd.to_s) end |
.subcommand_registry ⇒ Object
38 39 40 41 |
# File 'lib/fluid_cli/command.rb', line 38 def subcommand_registry @subcommand_registry ||= CLI::Kit::CommandRegistry.new( default: nil) end |