Class: Cumuli::CLI::RemoteCommand
- Inherits:
-
Object
- Object
- Cumuli::CLI::RemoteCommand
- Defined in:
- lib/cumuli/cli/remote_command.rb
Constant Summary collapse
- DIR_ENV =
'DIR='
- COMMAND_ENV =
'COMMAND='
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Instance Method Summary collapse
- #command ⇒ Object
- #dir ⇒ Object
- #extract_env(env_var) ⇒ Object
- #get_passed_command ⇒ Object
-
#initialize(argv) ⇒ RemoteCommand
constructor
A new instance of RemoteCommand.
- #perform ⇒ Object
- #raw_command ⇒ Object
Constructor Details
#initialize(argv) ⇒ RemoteCommand
Returns a new instance of RemoteCommand.
9 10 11 |
# File 'lib/cumuli/cli/remote_command.rb', line 9 def initialize(argv) @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
4 5 6 |
# File 'lib/cumuli/cli/remote_command.rb', line 4 def argv @argv end |
Instance Method Details
#command ⇒ Object
31 32 33 |
# File 'lib/cumuli/cli/remote_command.rb', line 31 def command Commander.new(raw_command).build end |
#dir ⇒ Object
18 19 20 |
# File 'lib/cumuli/cli/remote_command.rb', line 18 def dir extract_env(DIR_ENV) end |
#extract_env(env_var) ⇒ Object
13 14 15 16 |
# File 'lib/cumuli/cli/remote_command.rb', line 13 def extract_env(env_var) found_arg = argv.detect{|arg| arg.include?(env_var)} found_arg && found_arg.gsub(env_var, '') end |
#get_passed_command ⇒ Object
26 27 28 29 |
# File 'lib/cumuli/cli/remote_command.rb', line 26 def get_passed_command matched = argv.first.match(/\[(.*)\]/) (matched && matched[1]) || argv.first end |
#perform ⇒ Object
35 36 37 38 39 |
# File 'lib/cumuli/cli/remote_command.rb', line 35 def perform Dir.chdir(dir) do Terminal.new(command).spawn end end |
#raw_command ⇒ Object
22 23 24 |
# File 'lib/cumuli/cli/remote_command.rb', line 22 def raw_command extract_env(COMMAND_ENV) || get_passed_command end |