Class: Cumuli::CLI::RemoteRakeCommand

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ RemoteRakeCommand

Returns a new instance of RemoteRakeCommand.



9
10
11
12
# File 'lib/cumuli/cli/remote_rake_command.rb', line 9

def initialize(argv)
  puts "argv: #{argv.inspect}"
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



4
5
6
# File 'lib/cumuli/cli/remote_rake_command.rb', line 4

def argv
  @argv
end

Instance Method Details

#commandObject



32
33
34
# File 'lib/cumuli/cli/remote_rake_command.rb', line 32

def command
  Commander.new(raw_command).build
end

#dirObject



19
20
21
# File 'lib/cumuli/cli/remote_rake_command.rb', line 19

def dir
  extract_env(DIR_ENV)
end

#extract_env(env_var) ⇒ Object



14
15
16
17
# File 'lib/cumuli/cli/remote_rake_command.rb', line 14

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



27
28
29
30
# File 'lib/cumuli/cli/remote_rake_command.rb', line 27

def get_passed_command
  matched = argv.first.match(/\[(.*)\]/)
  (matched && matched[1]) || argv.first
end

#performObject



36
37
38
39
40
41
# File 'lib/cumuli/cli/remote_rake_command.rb', line 36

def perform
  Dir.chdir(dir) do
    puts "running #{command}, at #{dir}"
    Terminal.new(command).spawn
  end
end

#raw_commandObject



23
24
25
# File 'lib/cumuli/cli/remote_rake_command.rb', line 23

def raw_command
  extract_env(COMMAND_ENV) || get_passed_command
end