Class: Pik::Add
Instance Attribute Summary collapse
Attributes inherited from Command
#config, #debug, #options, #output, #version
Instance Method Summary
collapse
#initialize
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, #parse_options, #pik_version, #sh, summary
Instance Attribute Details
#interactive ⇒ Object
Returns the value of attribute interactive.
8
9
10
|
# File 'lib/pik/commands/add_command.rb', line 8
def interactive
@interactive
end
|
Instance Method Details
#add(path) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/pik/commands/add_command.rb', line 16
def add(path)
path = Pathname.new(path)
path = path.dirname if path.file?
if Which::Ruby.exist?(path)
if find_config_from_path(path)
puts "This version has already been added."
else
version = get_version(path)
version = modify_version(version) if config[version]
path = Pathname(path.expand_path.to_ruby)
puts "** Adding: #{version}\n Located at: #{path}\n"
@config[version] = {}
@config[version][:path] = path
end
else
puts "Couldn't find a Ruby version at #{path}"
end
end
|
#add_interactive ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/pik/commands/add_command.rb', line 44
def add_interactive
@hl.choose do ||
.prompt = ""
.choice('e]nter a path') do
dir = @hl.ask("Enter a path to a ruby/bin dir (enter to quit)")
execute(dir) unless dir.empty? || !@hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
add_interactive
end
.choice('s]earch') do
search_dir = @hl.ask("Enter a search path")
files = Which::Ruby.glob(search_dir + '**')
files.uniq.each do |file|
dir = File.dirname(file)
add(dir) if @hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
end
add_interactive
end
.choice('q]uit'){raise QuitError}
end
end
|
#command_options ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/pik/commands/add_command.rb', line 35
def command_options
super
options.banner += "[path_to_ruby]"
options.separator ""
options.on("--interactive", "-i", "Add interactively") do |value|
@interactive = value
end
end
|
#execute(path = nil) ⇒ Object
10
11
12
13
14
|
# File 'lib/pik/commands/add_command.rb', line 10
def execute(path=nil)
return add_interactive if interactive
path = @args.first || Which::Ruby.find
add(path)
end
|
#modify_version(version) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/pik/commands/add_command.rb', line 66
def modify_version(version)
puts "This version appears to exist in another location."
puts "Path: " + config[version][:path]
puts "If you'd still like to add this version, you can."
modifier = @hl.ask("Enter a unique name to modify the name of this version. (enter to quit)")
raise QuitError if modifier.empty?
ver = version.split(':')
["#{ver.shift}-#{modifier}", ver].join(':')
end
|