Class: Brut::CLI::Commands::CompoundCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Brut::CLI::Commands::CompoundCommand
- Defined in:
- lib/brut/cli/commands/compound_command.rb
Overview
A command that exists only to call other commands in order. This is useful if you want a convienience command to call two or more other commands. By default, each command must succeed for the others to be called.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
-
#execute(execution_context) ⇒ Object
Overrides the parent class to call each command in order.
-
#initialize(commands) ⇒ CompoundCommand
constructor
Create the compound command with the given list of commands.
Methods inherited from BaseCommand
#accepts, #args_description, #argv, #bootstrap?, #commands, #default_rack_env, #delegate_to_command, #description, #detailed_description, #env, #env_vars, #name, #options, #opts, #puts, #run, #stdin, #system!, #theme
Constructor Details
#initialize(commands) ⇒ CompoundCommand
Create the compound command with the given list of commands. Note that these commands will be executed with this commands ‘Brut::CLI::Commands::ExecutionContext`, so these commands should all be able to work with whatever command line arguments and `argv` would be provided.
8 9 10 |
# File 'lib/brut/cli/commands/compound_command.rb', line 8 def initialize(commands) @commands = commands end |
Instance Method Details
#execute(execution_context) ⇒ Object
Overrides the parent class to call each command in order. Note that if you subclass this class, **‘run` is not called**. If you want to perform custom logic, you must override this method, but take care to call methods on the passed `execution_context`. Methods like `puts`, `system!`, and `options` **will not work** here since they assume an ivar named `@execution_context` has been set.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/brut/cli/commands/compound_command.rb', line 16 def execute(execution_context) @commands.each do |command| execute_result = Brut::CLI::ExecuteResult.new do delegate_to_command(command,execution_context) end if execute_result.failed? return execute_result.actual_result end end 0 end |