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_command, #default_command_class, #default_rack_env, #description, #env, #env_vars, #name, #options, #opts, #puts, #run, #stderr, #stdin, #stdout, #system!
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 27 28 |
# 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 command.execute(execution_context) end if execute_result.failed? return execute_result.exit_status do || @stderr.puts end end end 0 end |