pik 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/History.txt +20 -0
  2. data/Manifest.txt +4 -1
  3. data/README.rdoc +40 -17
  4. data/Rakefile +68 -59
  5. data/bin/pik_install +42 -14
  6. data/features/add_command.feature +8 -8
  7. data/features/config_command.feature +1 -2
  8. data/features/default_command.feature +3 -3
  9. data/features/gemsync_command.feature +1 -1
  10. data/features/info_command.feature +62 -0
  11. data/features/install_command.feature +22 -17
  12. data/features/list_command.feature +5 -5
  13. data/features/pik_install.feature +34 -2
  14. data/features/remove_command.feature +2 -2
  15. data/features/run_command.feature +6 -5
  16. data/features/step_definitions/pik_commands.rb +21 -7
  17. data/features/support/env.rb +75 -0
  18. data/features/support/proxy.ru +81 -0
  19. data/features/switch_command.feature +14 -13
  20. data/features/tag_command.feature +5 -5
  21. data/features/uninstall_command.feature +5 -6
  22. data/features/version.feature +2 -1
  23. data/lib/pik.rb +13 -6
  24. data/lib/pik/commands/add_command.rb +13 -1
  25. data/lib/pik/commands/command.rb +6 -6
  26. data/lib/pik/commands/config_command.rb +4 -2
  27. data/lib/pik/commands/devkit_command.rb +69 -0
  28. data/lib/pik/commands/gemsync_command.rb +4 -2
  29. data/lib/pik/commands/help_command.rb +1 -1
  30. data/lib/pik/commands/info_command.rb +35 -14
  31. data/lib/pik/commands/install_command.rb +6 -11
  32. data/lib/pik/commands/list_command.rb +26 -7
  33. data/lib/pik/commands/uninstall_command.rb +4 -4
  34. data/lib/pik/contrib/uri_ext.rb +1 -1
  35. data/lib/pik/core_ext/pathname.rb +2 -2
  36. data/lib/pik/implementations.rb +51 -7
  37. data/lib/pik/version_parser.rb +8 -5
  38. data/spec/html/ruby.htm +61 -15
  39. data/spec/implementations_spec.rb +4 -4
  40. data/spec/pathname_spec.rb +12 -4
  41. data/spec/version_parser_spec.rb +9 -2
  42. data/tools/pik.bat +1 -1
  43. data/tools/pik/pik_runner +1 -1
  44. data/tools/pik/pik_runner.exe +0 -0
  45. data/tools/pik/pik_runner.exy +121 -114
  46. metadata +58 -15
  47. data/features/env.rb +0 -45
@@ -7,4 +7,5 @@ Feature: display pik version
7
7
  Scenario: Listing versions
8
8
  When I run "pik -V"
9
9
  Then I should see "pik "
10
- And I should see the Pik::VERSION
10
+ And I should see the Pik::VERSION
11
+ And I should not see "Usage: pik command [options]"
data/lib/pik.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  module Pik
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
-
7
- ENV['GEM_HOME'] = nil
8
- ENV['GEM_PATH'] = nil
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'vendor/lib'))
9
7
 
10
8
  require 'yaml'
11
9
  require 'pathname'
@@ -13,7 +11,16 @@ require 'fileutils'
13
11
  require 'find'
14
12
  require 'open-uri'
15
13
  require 'rbconfig'
16
- require 'rubygems'
14
+
15
+ ENV['GEM_HOME'] = nil
16
+ ENV['GEM_PATH'] = nil
17
+ # real_home = ENV['HOME']
18
+ # ENV['HOME'] = "nul"
19
+
20
+ # require 'rubygems'
21
+
22
+ # ENV['HOME'] = real_home
23
+
17
24
  require 'hpricot'
18
25
  require 'highline'
19
26
 
@@ -24,6 +31,7 @@ require 'pik/commands'
24
31
  require 'pik/commands/config_file_editor'
25
32
  require 'pik/commands/batch_file_editor'
26
33
  require 'pik/commands/command'
34
+ require 'pik/commands/devkit_command'
27
35
  require 'pik/commands/install_command'
28
36
  require 'pik/commands/list_command'
29
37
  require 'pik/commands/add_command'
@@ -46,7 +54,6 @@ require 'pik/version_parser'
46
54
  require 'pik/windows_env'
47
55
  require 'pik/which'
48
56
 
49
-
50
57
  PIK_HOME = Pathname.new( ENV['HOME'] || ENV['USERPROFILE'] ) + '.pik'
51
58
 
52
59
  if defined? ExerbRuntime
@@ -16,11 +16,12 @@ module Pik
16
16
  def add(path)
17
17
  path = Pathname.new(path)
18
18
  path = path.dirname if path.file?
19
- if Which::Ruby.exist?(path)
19
+ if Which::Ruby.exist?(path)
20
20
  if find_config_from_path(path)
21
21
  puts "This version has already been added."
22
22
  else
23
23
  version = get_version(path)
24
+ version = modify_version(version) if config[version]
24
25
  path = Pathname(path.expand_path.to_ruby)
25
26
  puts "** Adding: #{version}\n Located at: #{path}\n"
26
27
  @config[version] = {}
@@ -61,6 +62,17 @@ module Pik
61
62
  end
62
63
 
63
64
  end
65
+
66
+ def modify_version(version)
67
+ puts "This version appears to exist in another location."
68
+ puts "Path: " + config[version][:path]
69
+ puts "If you'd still like to add this version, you can."
70
+ modifier = @hl.ask("Enter a unique name to modify the name of this version. (enter to quit)")
71
+ raise QuitError if modifier.empty?
72
+ ver = version.split(':')
73
+ ["#{ver.shift}-#{modifier}", ver].join(':')
74
+ end
75
+
64
76
  end
65
77
 
66
78
  end
@@ -60,7 +60,7 @@ module Pik
60
60
  if patterns.empty?
61
61
  possibles = config.keys
62
62
  else
63
- possibles = patterns.map{|p| config.keys.grep(Regexp.new(Regexp.escape(p.to_s))) }
63
+ possibles = patterns.map{|p| config.keys.grep(Regexp.new(Regexp.escape(p.to_s),Regexp::IGNORECASE) ) }
64
64
  possibles = possibles.inject{|m,v| m & v }.flatten.uniq
65
65
  end
66
66
  case possibles.size
@@ -108,6 +108,7 @@ module Pik
108
108
 
109
109
  def parse_options
110
110
  options.on("--version", "-V", "Pik version") do |value|
111
+ @version = true
111
112
  puts pik_version
112
113
  end
113
114
  options.on("--debug", "-d", "Outputs debug information") do |value|
@@ -145,16 +146,15 @@ module Pik
145
146
  end
146
147
 
147
148
  def default_gem_home
148
- get_gem_home(:first)
149
+ gem_path.first
149
150
  end
150
151
 
151
152
  def actual_gem_home
152
- get_gem_home(:last)
153
+ gem_path.last
153
154
  end
154
155
 
155
- def get_gem_home(position)
156
- path = `#{Which::Ruby.exe} -rubygems -e\"require 'rubygems' ; puts Gem.default_path.#{position}\"`
157
- Pathname.new(path.chomp).to_windows
156
+ def gem_path
157
+ `\"#{Which::Gem.exe}\" env gempath`.chomp.split(';').map{|p| Pathname(p).to_windows }
158
158
  end
159
159
 
160
160
  def create(home)
@@ -19,14 +19,16 @@ module Pik
19
19
  end
20
20
  when 'gem_home'
21
21
  config[find_config_from_path][:gem_home] = if @args.include?('default')
22
- Pathname.new(default_gem_home)
22
+ Pathname(default_gem_home)
23
23
  else
24
- Pathname.new(value)
24
+ Pathname(value)
25
25
  end
26
26
  when 'downloads', 'download_dir'
27
27
  config.global[:download_dir] = Pathname.new(value)
28
28
  when 'installs', 'install_dir'
29
29
  config.global[:install_dir] = Pathname.new(value)
30
+ when 'devkit', 'devkit_dir'
31
+ config.global[:devkit] = Pathname.new(value)
30
32
  when 'list'
31
33
  list
32
34
  else
@@ -0,0 +1,69 @@
1
+ module Pik
2
+
3
+ class Devkit < Command
4
+
5
+ it "Configures devkit settings"
6
+
7
+ def execute
8
+ if @args.include? 'update'
9
+ puts "Updating devkit batch files for:"
10
+ config.each{|ruby_version, ruby_config|
11
+ ver = Pik::VersionParser.parse(ruby_version)
12
+ if ver.platform =~ /mingw/
13
+ puts " #{ver.full_version}"
14
+ write_batch_files(ruby_config[:path])
15
+ end
16
+ config.global[:devkit]
17
+ }
18
+ else
19
+ help
20
+ end
21
+ end
22
+
23
+ def write_batch_files(path)
24
+ write_make(path)
25
+ write_sh(path)
26
+ write_gcc(path)
27
+ end
28
+
29
+ def write_make(path)
30
+ BatchFile.new(path + 'make.bat') do |b|
31
+ b.file_data << 'setlocal'
32
+ b.set(:DEVKIT => config.global[:devkit])
33
+ b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%DEVKIT%\\msys\\1.0.11\\bin")
34
+ b.file_data << "bash.exe --login -i -c \"make %*\""
35
+ b.write
36
+ end
37
+ end
38
+
39
+ def write_sh(path)
40
+ BatchFile.new(path + 'sh.bat') do |b|
41
+ b.file_data << 'setlocal'
42
+ b.set(:DEVKIT => config.global[:devkit])
43
+ b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%DEVKIT%\\msys\\1.0.11\\bin")
44
+ b.file_data << "bash.exe --login -i -c \"sh %*\""
45
+ b.write
46
+ end
47
+ end
48
+
49
+ def write_gcc(path)
50
+ BatchFile.new(path + 'sh.bat') do |b|
51
+ b.file_data << 'setlocal'
52
+ b.set(:DEVKIT => config.global[:devkit])
53
+ b.set(:PATH => "%DEVKIT%\\gcc\\3.4.5\\bin;%PATH%")
54
+ b.file_data << "gcc.exe %*"
55
+ b.write
56
+ end
57
+ end
58
+
59
+ def command_options
60
+ super
61
+ sep =<<SEP
62
+ SEP
63
+ options.separator sep
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
@@ -71,8 +71,10 @@ MSG
71
71
  conf = config[version]
72
72
  cmd = Which::Ruby.exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
73
73
 
74
- path = conf[:gem_home] ? Pathname( conf[:gem_home] ) : Pathname( `#{cmd}`.chomp )
75
- path + "cache"
74
+ path = conf[:gem_home] ? Pathname( conf[:gem_home] ) : Pathname( `#{cmd}`.chomp )
75
+ cache = path + "cache"
76
+ puts "cache: #{cache}" if debug
77
+ cache
76
78
  end
77
79
 
78
80
  def command_options
@@ -24,7 +24,7 @@ module Pik
24
24
  end
25
25
 
26
26
  def command_options
27
- options.program_name = "#{PIK_BATCH.basename('.*')} command"
27
+ options.program_name = "pik command"
28
28
  sep = <<SEP
29
29
 
30
30
  To get help with a command
@@ -7,18 +7,16 @@ module Pik
7
7
  aka :checkup, :cu
8
8
 
9
9
  def execute
10
- puts info
11
- end
12
-
13
- def info
14
- ruby = Which::Ruby.exe
15
- ruby_version = find_config_from_path(ruby.dirname)
10
+ puts pik_version
11
+
12
+ ruby = check_path
13
+
14
+ ruby_version = find_config_from_path(ruby)
16
15
  current = config[ruby_version]
17
16
  gem_home = current[:gem_home] || actual_gem_home
18
17
  ruby_version = Pik::VersionParser.parse(ruby_version)
19
18
 
20
- return info =<<INFO
21
- #{pik_version}
19
+ puts info =<<INFO
22
20
 
23
21
  ruby:
24
22
  interpreter: "#{ruby_version.interpreter}"
@@ -30,7 +28,7 @@ full_version: "#{ruby_version.full_version}"
30
28
 
31
29
  homes:
32
30
  gem: "#{gem_home}"
33
- ruby: "#{ruby.dirname.dirname}"
31
+ ruby: "#{ruby.dirname}"
34
32
 
35
33
  binaries:
36
34
  ruby: "#{ruby}"
@@ -46,24 +44,47 @@ RUBYOPT: "#{ENV['RUBYOPT']}"
46
44
 
47
45
  file associations:
48
46
  .rb: #{file_associations('.rb')}
49
- .rbw: #{file_associations('.rbw')}#{check_path}
47
+ .rbw: #{file_associations('.rbw')}
50
48
  INFO
51
49
  end
52
50
 
53
51
  def check_path
54
52
  dirs = Which::Ruby.find_all
55
- unless dirs.size == 1
56
- dirs.unshift("\n\nwarning: There is more than one version of ruby in the system path")
57
- dirs.join("\n")
53
+ case dirs.size
54
+ when 0
55
+ $stdout.flush
56
+ abort no_ruby
57
+ when 1
58
+ dirs.first
59
+ else
60
+ puts too_many_rubies(dirs)
61
+ dirs.first
58
62
  end
59
63
  end
60
64
 
65
+ def too_many_rubies(dirs)
66
+ msg =<<MSG
67
+
68
+ warning: There is more than one version of ruby in the system path
69
+ #{dirs.join("\n")}
70
+ MSG
71
+ end
72
+
73
+ def no_ruby
74
+ msg =<<MSG
75
+
76
+ Pik info will not work unless there is a version of ruby in the path.
77
+
78
+ You can use pik switch to add one.
79
+ MSG
80
+ end
81
+
61
82
  def file_associations(extension)
62
83
  @reg = Reg.new
63
84
  assoc = @reg.hkcr(extension) rescue nil
64
85
  ftype = @reg.hkcr("#{assoc}\\Shell\\open\\command") rescue nil
65
86
  end
66
-
87
+
67
88
  end
68
89
 
69
90
  end
@@ -9,6 +9,8 @@ module Pik
9
9
  aka :in
10
10
  it "Downloads and installs different ruby versions."
11
11
 
12
+ attr_reader :target
13
+
12
14
  def initialize(args=ARGV, config_=nil)
13
15
  super
14
16
  @download_dir = config.global[:download_dir] || PIK_HOME + 'downloads'
@@ -18,11 +20,11 @@ module Pik
18
20
 
19
21
  def execute
20
22
  implementation = Implementations[@args.shift]
21
- target, package = implementation.find(*@args)
22
- target = @install_root + "#{implementation.name}-#{target.gsub('.','')}"
23
+ @target, package = implementation.find(*@args)
24
+ @target = @install_root + "#{implementation.name}-#{@target.gsub('.','')}"
23
25
  file = download(package)
24
- extract(target, file)
25
- add( Pathname(target) + 'bin' )
26
+ extract(@target, file)
27
+ implementation.after_install(self)
26
28
  end
27
29
 
28
30
  def command_options
@@ -63,13 +65,6 @@ SEP
63
65
  end
64
66
  end
65
67
 
66
- def add(path)
67
- puts
68
- p = Pik::Add.new([path], config)
69
- p.execute
70
- p.close
71
- end
72
-
73
68
  def seven_zip(target, file)
74
69
  file = Pathname(file)
75
70
  seven_zip = Which::SevenZip.exe.basename
@@ -20,19 +20,38 @@ module Pik
20
20
  end
21
21
 
22
22
  def list
23
- current_path = Which::Ruby.find
23
+
24
24
  config.sort.each do |name, conf|
25
- name += ' *' if current_path == conf[:path]
26
- puts name
27
- if verbose
28
- conf.each{|k,v| puts " %s: %s" % [k, v]}
29
- puts
30
- end
25
+ puts layout(name, conf)
26
+ puts conf.map{|k,v| " %s: %s" % [k, v]} + ["\n"] if verbose
27
+
31
28
  end
32
29
  end
33
30
 
34
31
  private
35
32
 
33
+ def layout(name, conf)
34
+ name = current?(conf) ? "* #{name}" : " #{name}"
35
+ if name.length > columns
36
+ remainder = -(name.length - columns + 5)
37
+ "#{name[0,columns-5]}...#{" ...%s" % name[remainder..-1] if verbose}"
38
+ else
39
+ name
40
+ end
41
+ end
42
+
43
+ def current?(conf)
44
+ current_path == conf[:path]
45
+ end
46
+
47
+ def current_path
48
+ @current_path ||= Which::Ruby.find
49
+ end
50
+
51
+ def columns
52
+ @hl.output_cols
53
+ end
54
+
36
55
  def command_options
37
56
  super
38
57
  @options.on("--verbose", "-v",
@@ -15,21 +15,21 @@ module Pik
15
15
  puts "** Deleting #{config[to_remove][:path].dirname}"
16
16
  path = config[to_remove][:path].dirname
17
17
  FileUtils.rm_rf(path) if path.exist?
18
- remove
18
+ remove(to_remove)
19
19
  puts
20
20
  @hl.say("#{to_remove} has been uninstalled.")
21
21
  end
22
22
  end
23
23
 
24
- def remove
25
- rm = Pik::Remove.new(@args + ['--force', '--quiet'], config)
24
+ def remove(to_remove)
25
+ rm = Pik::Remove.new([to_remove, '--force', '--quiet'], config)
26
26
  rm.execute
27
27
  rm.close
28
28
  end
29
29
 
30
30
  def command_options
31
31
  super
32
- options.on("--force", "-f", "Remove without prompting") do |value|
32
+ options.on("--force", "-f", "Uninstall without prompting") do |value|
33
33
  @force = value
34
34
  end
35
35
  end
@@ -8,7 +8,7 @@
8
8
  require 'cgi'
9
9
  require 'uri'
10
10
  require 'net/http'
11
- require 'net/https'
11
+ # require 'net/https'
12
12
  require 'tempfile'
13
13
  require 'fileutils'
14
14
 
@@ -2,12 +2,12 @@
2
2
  class Pathname
3
3
 
4
4
  def to_s
5
- @path.tr('/','\\')
5
+ @path.tr('/','\\').sub(/^.:/){|s| s.upcase }
6
6
  end
7
7
  alias to_windows to_s
8
8
 
9
9
  def to_ruby
10
- @path.tr('\\','/')
10
+ @path.tr('\\','/').sub(/^.:/){|s| s.upcase }
11
11
  end
12
12
 
13
13
  def ruby