Class: Pik::Run
Instance Attribute Summary
Attributes inherited from Command
#config, #debug, #options, #output, #version
Instance Method Summary
collapse
Methods inherited from Command
#actual_gem_home, #add_sigint_handler, aka, choose_from, #close, #cmd_name, cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_script, description, #editors, #find_config_from_path, #gem_path, #get_version, hl, inherited, #initialize, it, names, #pik_version, #sh, summary
Constructor Details
This class inherits a constructor from Pik::Command
Instance Method Details
#args_required? ⇒ Boolean
83
84
85
|
# File 'lib/pik/commands/run_command.rb', line 83
def args_required?
true
end
|
#check_args ⇒ Object
77
78
79
80
81
|
# File 'lib/pik/commands/run_command.rb', line 77
def check_args
if args_required? && @args.empty?
raise "The #{cmd_name} command must be called with an argument"
end
end
|
#command(cmd = 'CALL') ⇒ Object
24
25
26
27
|
# File 'lib/pik/commands/run_command.rb', line 24
def command(cmd='CALL')
args = @args.map{|a| a.sub(/.*\s.*/m, '"\&"')}.join(' ')
"#{cmd} #{args}"
end
|
#command_options ⇒ Object
30
31
32
33
|
# File 'lib/pik/commands/run_command.rb', line 30
def command_options
super
options.separator help_message
end
|
#echo_ruby_version(path) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/pik/commands/run_command.rb', line 70
def echo_ruby_version(path)
rb = Which::Ruby.exe(path)
raise "Unable to find a Ruby executable at #{path}" unless rb
puts `"#{rb}" -v `
puts
end
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/pik/commands/run_command.rb', line 7
def execute
check_args
@config.sort.each do |version,hash|
begin
switch_path_to(hash)
switch_gem_home_to(hash[:gem_home])
echo_ruby_version(hash[:path])
system command
puts
rescue => e
version = version.split(': ')[1..-1].join(': ')
puts version
Pik.print_error(e)
end
end
end
|
#help_message ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/pik/commands/run_command.rb', line 35
def help_message
sep =<<SEP
Examples:
C:\\>pik run PATH
C:\\>pik run rake spec
SEP
end
|
#parse_options ⇒ Object
46
47
|
# File 'lib/pik/commands/run_command.rb', line 46
def parse_options
end
|
#switch_gem_home_to(gem_home) ⇒ Object
64
65
66
67
68
|
# File 'lib/pik/commands/run_command.rb', line 64
def switch_gem_home_to(gem_home)
gem_home = Pathname(gem_home).to_windows rescue nil
ENV['GEM_PATH'] = gem_home
ENV['GEM_HOME'] = gem_home
end
|
#switch_path_to(other) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/pik/commands/run_command.rb', line 49
def switch_path_to(other)
current = Which::Ruby.find
new_path = SearchPath.new(ENV['PATH'])
new_path.replace_or_add(current, other[:path])
new_path.remove(Pathname.new(ENV['GEM_HOME']) + 'bin') if ENV['GEM_HOME']
new_path.add(Pathname.new(other[:gem_home]) + 'bin') if other[:gem_home]
ENV['PATH'] = new_path.join
end
|