Class: Cumuli::CLI::RemoteCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/cumuli/cli/remote_command.rb

Constant Summary collapse

DIR_ENV =
'DIR='
COMMAND_ENV =
'COMMAND='

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argvObject (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

#commandObject



31
32
33
# File 'lib/cumuli/cli/remote_command.rb', line 31

def command
  Commander.new(raw_command).build
end

#dirObject



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_commandObject



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

#performObject



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_commandObject



22
23
24
# File 'lib/cumuli/cli/remote_command.rb', line 22

def raw_command
  extract_env(COMMAND_ENV) || get_passed_command
end