Class: Conductor::Command
- Inherits:
-
Object
- Object
- Conductor::Command
- Defined in:
- lib/conductor/command.rb
Overview
Command runner
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(command) ⇒ Command
constructor
Instantiate a command runner.
-
#run ⇒ String
Run the command.
Constructor Details
#initialize(command) ⇒ Command
Instantiate a command runner
13 14 15 16 17 |
# File 'lib/conductor/command.rb', line 13 def initialize(command) parts = Shellwords.split(command) self.path = parts[0] self.args = parts[1..].join(" ") end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/conductor/command.rb', line 6 def args @args end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/conductor/command.rb', line 6 def path @path end |
Instance Method Details
#run ⇒ String
Run the command
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/conductor/command.rb', line 55 def run stdin = Conductor.stdin raise "Command path not found" unless @path use_stdin = true if /\$\{?file\}?/.match?(args) use_stdin = false args.sub!(/\$\{?file\}?/, %("#{Env.env[:filepath]}")) else raise "No input" unless stdin end if use_stdin `echo #{Shellwords.escape(stdin.utf8)} | #{Env} #{path} #{args}` else `#{Env} #{path} #{args}` end end |