Class: Pik::Add
Instance Attribute Summary collapse
Attributes inherited from Command
#config, #options, #output, #version
Instance Method Summary
collapse
#initialize
Methods inherited from Command
#add_sigint_handler, aka, choose_from, clean_gem_batch, #close, cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_batches, description, #editors, #find_config_from_path, #get_version, hl, inherited, #initialize, it, names, #parse_options, 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
|
# 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)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/pik/commands/add_command.rb', line 43
def add_interactive
@hl.choose do ||
.prompt = ""
.choice('e]nter a path'){
dir = @hl.ask("Enter a path to a ruby/bin dir (enter to quit)")
execute(dir) unless dir.empty? || !@hl.agree("Add '#{dir}'? [Yn] ")
add_interactive
}
.choice('s]earch'){
search_dir = @hl.ask("Enter a search path")
files = Which::Ruby.glob(search_dir + '**')
files.each{|file|
dir = File.dirname(file)
add(dir) if @hl.agree("Add '#{dir}'? [Yn] ")
}
add_interactive
}
.choice('q]uit'){raise QuitError}
end
end
|
#command_options ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/pik/commands/add_command.rb', line 34
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
|