Class: Bard::Command
- Inherits:
-
Struct
- Object
- Struct
- Bard::Command
- Defined in:
- lib/bard/command.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#home ⇒ Object
Returns the value of attribute home.
-
#on ⇒ Object
Returns the value of attribute on.
Class Method Summary collapse
- .exec!(command, on: :local, home: false) ⇒ Object
- .run(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object
- .run!(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object
Instance Method Summary collapse
- #exec! ⇒ Object
- #run(verbose: false, quiet: false) ⇒ Object
- #run!(verbose: false, quiet: false) ⇒ Object
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command
4 5 6 |
# File 'lib/bard/command.rb', line 4 def command @command end |
#home ⇒ Object
Returns the value of attribute home
4 5 6 |
# File 'lib/bard/command.rb', line 4 def home @home end |
#on ⇒ Object
Returns the value of attribute on
4 5 6 |
# File 'lib/bard/command.rb', line 4 def on @on end |
Class Method Details
.exec!(command, on: :local, home: false) ⇒ Object
15 16 17 |
# File 'lib/bard/command.rb', line 15 def self.exec! command, on: :local, home: false new(command, on, home).exec! end |
.run(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object
11 12 13 |
# File 'lib/bard/command.rb', line 11 def self.run command, on: :local, home: false, verbose: false, quiet: false new(command, on, home).run verbose:, quiet: end |
.run!(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object
7 8 9 |
# File 'lib/bard/command.rb', line 7 def self.run! command, on: :local, home: false, verbose: false, quiet: false new(command, on, home).run! verbose:, quiet: end |
Instance Method Details
#exec! ⇒ Object
39 40 41 |
# File 'lib/bard/command.rb', line 39 def exec! exec full_command end |
#run(verbose: false, quiet: false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bard/command.rb', line 25 def run verbose: false, quiet: false if verbose system full_command(quiet: quiet) else stdout, stderr, status = Open3.capture3(full_command) failed = status.to_i.nonzero? if failed && !quiet $stdout.puts stdout $stderr.puts stderr end !failed && stdout end end |
#run!(verbose: false, quiet: false) ⇒ Object
19 20 21 22 23 |
# File 'lib/bard/command.rb', line 19 def run! verbose: false, quiet: false if !run(verbose:, quiet:) raise Error.new(full_command) end end |