Class: Protobox::Cli
- Inherits:
-
Object
- Object
- Protobox::Cli
- Defined in:
- lib/protobox/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
-
.execute(*args) ⇒ Object
Shortcut.
Instance Method Summary collapse
-
#exec(*args) ⇒ Object
Special-case ‘echo` for Windows.
- #execute ⇒ Object
-
#execute_command_chain(commands) ⇒ Object
Runs multiple commands in succession; exits at first failure.
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
5 6 7 8 |
# File 'lib/protobox/cli.rb', line 5 def initialize(*args) #@args = Args.new(args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/protobox/cli.rb', line 3 def args @args end |
Class Method Details
.execute(*args) ⇒ Object
Shortcut
11 12 13 |
# File 'lib/protobox/cli.rb', line 11 def self.execute(*args) new(*args).execute end |
Instance Method Details
#exec(*args) ⇒ Object
Special-case ‘echo` for Windows
34 35 36 37 38 39 40 |
# File 'lib/protobox/cli.rb', line 34 def exec *args if args.first == 'echo' && Util::Context.windows? puts args[1..-1].join(' ') else super end end |
#execute ⇒ Object
15 16 17 |
# File 'lib/protobox/cli.rb', line 15 def execute Commands.run(@args) end |
#execute_command_chain(commands) ⇒ Object
Runs multiple commands in succession; exits at first failure.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/protobox/cli.rb', line 20 def execute_command_chain commands commands.each_with_index do |cmd, i| if cmd.respond_to?(:call) then cmd.call elsif i == commands.length - 1 # last command in chain STDOUT.flush; STDERR.flush exec(*cmd) else exit($?.exitstatus) unless system(*cmd) end end end |