pik 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ === 0.2.6 / 2009-11-08
2
+
3
+ * deprecated checkup command in favor of info command
4
+ * added info command
5
+ * added benchmark command
6
+ * fixes to gemsync command
7
+ * don't need to be admin to run pik default
8
+ * added update command
9
+ * gemsync command - platform aware - remote option - quiet option
10
+
1
11
 
2
12
  === 0.2.5 / 2009-10-29
3
13
 
@@ -22,11 +22,9 @@ features/uninstall_command.feature
22
22
  features/version.feature
23
23
  lib/pik.rb
24
24
  lib/pik/batch_file.rb
25
- lib/pik/checkup.rb
26
25
  lib/pik/commands.rb
27
26
  lib/pik/commands/add_command.rb
28
27
  lib/pik/commands/batch_file_editor.rb
29
- lib/pik/commands/checkup_command.rb
30
28
  lib/pik/commands/command.rb
31
29
  lib/pik/commands/config_command.rb
32
30
  lib/pik/commands/config_file_editor.rb
@@ -34,6 +32,7 @@ lib/pik/commands/default_command.rb
34
32
  lib/pik/commands/gemsync_command.rb
35
33
  lib/pik/commands/help_command.rb
36
34
  lib/pik/commands/implode_command.rb
35
+ lib/pik/commands/info_command.rb
37
36
  lib/pik/commands/install_command.rb
38
37
  lib/pik/commands/list_command.rb
39
38
  lib/pik/commands/remove_command.rb
@@ -41,6 +40,7 @@ lib/pik/commands/run_command.rb
41
40
  lib/pik/commands/switch_command.rb
42
41
  lib/pik/commands/tag_command.rb
43
42
  lib/pik/commands/uninstall_command.rb
43
+ lib/pik/commands/update_command.rb
44
44
  lib/pik/config_file.rb
45
45
  lib/pik/contrib/progressbar.rb
46
46
  lib/pik/contrib/unzip.rb
@@ -56,6 +56,7 @@ lib/pik/implementations.rb
56
56
  lib/pik/options.rb
57
57
  lib/pik/pik.rb
58
58
  lib/pik/search_path.rb
59
+ lib/pik/version_parser.rb
59
60
  lib/pik/which.rb
60
61
  lib/pik/windows_env.rb
61
62
  spec/add_command_spec.rb
@@ -76,6 +77,7 @@ spec/run_command_spec.rb
76
77
  spec/search_path_spec.rb
77
78
  spec/spec.opts
78
79
  spec/switch_command_spec.rb
80
+ spec/version_parser_spec.rb
79
81
  spec/which_spec.rb
80
82
  tools/pik.bat
81
83
  tools/pik/pik_runner
@@ -12,49 +12,33 @@ Gordon Thiesfeld
12
12
 
13
13
  == DESCRIPTION:
14
14
 
15
- Pik is a tool to switch between multiple versions of ruby on Windows.
15
+ Pik is a tool to manage multiple versions of ruby on Windows.
16
16
 
17
- Or to put it another way
18
-
19
- doskey rvm=pik $* # (sort of)
20
-
21
- You have to tell it where your different ruby versions live using
22
- 'pik add'. Then you can change to one by using 'pik switch'.
23
-
24
- It also supports running commands/code with all versions configured.
25
-
26
- pik run # Runs commands on the command line
27
- pik ruby # Runs using the ruby interpreter for each version (ruby.exe, jruby.bat, ir.exe)
28
- pik gem # Runs using the gem command for each version (gem.bat, igem.bat)
29
- pik rake # Runs using the rake command for each version (rake.bat, irake.bat)
30
-
31
-
32
- == FEATURES/PROBLEMS:
33
-
34
-
35
- == SYNOPSIS:
36
-
37
- >pik help commands
38
-
39
- add Adds another ruby location to pik.
40
- checkup|cu Checks your environment for current Ruby best practices.
41
- config Adds/modifies configuration options.
42
- default Switches back to the default settings.
43
- gem Runs the gem command with all versions that pik is aware of.
44
- gemsync Duplicates gems from the current version to the one specified.
45
- help Displays help information.
46
- implode Removes your pik configuration.
47
- install|in Downloads and installs different ruby versions.
48
- list|ls Lists ruby versions that pik is aware of.
49
- rake Runs the rake command with all versions that pik is aware of.
50
- remove|rm Removes a ruby location from pik.
51
- ruby|rb Runs ruby with all versions that pik is aware of.
52
- run Runs command with all versions of ruby that pik is aware of.
53
- switch|sw|use Switches ruby versions based on patterns.
54
- tag Adds the given tag to the current version.
55
- tags Runs the pik command against the given tags.
56
-
57
- For help on a particular command, use 'pik help COMMAND'.
17
+ >pik help commands
18
+
19
+ add Adds another ruby location to pik.
20
+ benchmark|bench Runs bencmarks with all versions that pik is aware of.
21
+ checkup|cu Checks your environment for current Ruby best practices.
22
+ config Adds/modifies configuration options.
23
+ default Switches back to the default settings.
24
+ gem Runs the gem command with all versions that pik is aware of.
25
+ gemsync Synchronizes gems from the version specified to the current version.
26
+ help Displays help information.
27
+ implode Removes your pik configuration.
28
+ info Displays information about the current ruby version.
29
+ install|in Downloads and installs different ruby versions.
30
+ list|ls Lists ruby versions that pik is aware of.
31
+ rake Runs the rake command with all versions that pik is aware of.
32
+ remove|rm Removes a ruby location from pik.
33
+ ruby|rb Runs ruby with all versions that pik is aware of.
34
+ run Runs command with all versions of ruby that pik is aware of.
35
+ switch|sw|use Switches ruby versions based on patterns.
36
+ tag Adds the given tag to the current version.
37
+ tags Runs the pik command against the given tags.
38
+ uninstall|unin Deletes a ruby version from the filesystem and removes it from Pik.
39
+ update|up updates pik.
40
+
41
+ For help on a particular command, use 'pik help COMMAND'.
58
42
 
59
43
  == REQUIREMENTS:
60
44
 
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
  file 'tools/pik/pik.exe', :needs => ['tools/pik/pik_runner.exy'] do
23
23
  Dir.chdir 'tools/pik' do
24
24
  sh('ruby -S exerb pik_runner.exy')
25
- sh('upx -9 pik_runner.exe')
25
+ sh('upx -9 pik_runner.exe') unless ENV['QUICK']
26
26
  end
27
27
  end
28
28
 
@@ -0,0 +1,19 @@
1
+ Feature: gemsync command
2
+ In order to test code against specific ruby implementations
3
+ A developer
4
+ Wants an interface to the program
5
+ So that he can tag versions that pik is aware of
6
+
7
+ Scenario: sync to previous version
8
+ Given I only have the rake gem installed to version 1.9.1.
9
+ When I run "pik 191 mi" and "pik gemsync 186 mi -q -d",
10
+ Then I should see "** Syncing"
11
+ And I should find "Gem rake.+ already installed"
12
+ And I should see "Installing hoe"
13
+
14
+ Scenario: attempt to sync to different platform
15
+ When I run "pik Ir 91" and "pik gemsync 186 mi -q -d",
16
+ Then I should see "You appear to be attempting a gemsync from a different platform."
17
+
18
+
19
+ # Scenaorio: sync remotely
@@ -7,6 +7,17 @@ Given /^I have.+added "(.+)"/ do |version|
7
7
  @ver.size.should eql(1)
8
8
  end
9
9
 
10
+ Given /^I only have the rake gem installed to version 1\.9\.1\.$/ do
11
+ x = `pik 191 & gem list`.split("\n").map{|gem_| gem_.split(' ') }
12
+ x.map! do |name, version|
13
+ unless name == 'rake'
14
+ `pik 191 & gem unin #{name} -x -I`
15
+ name
16
+ end
17
+ end
18
+ x.should_not include('rake')
19
+ end
20
+
10
21
  Given /^I am currently using it\.$/ do
11
22
  unless `ruby -v` =~ @version_reg
12
23
  k,v = `pik switch #{@version} & path`.split('=')
data/lib/pik.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Pik
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -10,6 +10,7 @@ ENV['GEM_PATH'] = nil
10
10
  require 'yaml'
11
11
  require 'pathname'
12
12
  require 'fileutils'
13
+ require 'find'
13
14
  require 'open-uri'
14
15
  require 'rbconfig'
15
16
  require 'rubygems'
@@ -27,19 +28,21 @@ require 'pik/commands/install_command'
27
28
  require 'pik/commands/list_command'
28
29
  require 'pik/commands/add_command'
29
30
  require 'pik/commands/help_command'
31
+ require 'pik/commands/info_command'
30
32
  require 'pik/commands/switch_command'
31
33
  require 'pik/commands/run_command'
32
34
  require 'pik/commands/remove_command'
33
- require 'pik/commands/checkup_command'
34
35
  require 'pik/commands/config_command'
35
36
  require 'pik/commands/gemsync_command'
36
37
  require 'pik/commands/default_command'
37
38
  require 'pik/commands/implode_command'
38
39
  require 'pik/commands/tag_command'
39
40
  require 'pik/commands/uninstall_command'
41
+ require 'pik/commands/update_command'
40
42
  require 'pik/config_file'
41
43
  require 'pik/implementations'
42
44
  require 'pik/search_path'
45
+ require 'pik/version_parser'
43
46
  require 'pik/windows_env'
44
47
  require 'pik/which'
45
48
 
@@ -52,3 +55,6 @@ else
52
55
  pik_exe = Pathname.new($0).expand_path + '..'
53
56
  PIK_BATCH = pik_exe.dirname + "#{pik_exe.basename}.bat"
54
57
  end
58
+
59
+ Pik::Commands.deprecate(:checkup => "The checkup command is deprecated, using the info command instead.")
60
+ Pik::Commands.deprecate(:cu => "The cu command is deprecated, using the info command instead.")
@@ -49,7 +49,7 @@ class BatchFile
49
49
  self
50
50
  end
51
51
 
52
- def echo(string)
52
+ def echo(string='.')
53
53
  string = ' ' + string unless string == '.'
54
54
  @file_data << "ECHO#{string}"
55
55
  self
@@ -11,7 +11,9 @@ module Pik
11
11
  end
12
12
 
13
13
  def self.find(command)
14
- commands.find{ |cmd| cmd.names.include?(command.to_sym) }
14
+ command = command.to_sym
15
+ puts deprecated[command] if deprecated[command]
16
+ commands.find{ |cmd| cmd.names.include?(command) }
15
17
  end
16
18
 
17
19
  def self.list
@@ -29,7 +31,14 @@ module Pik
29
31
  @commands ||= []
30
32
  end
31
33
 
32
-
34
+ def self.deprecate(command)
35
+ deprecated.update command
36
+ end
37
+
38
+ def self.deprecated
39
+ @deprecated ||= {}
40
+ end
41
+
33
42
  end
34
43
 
35
44
  end
@@ -18,6 +18,8 @@ module Pik
18
18
 
19
19
  attr_accessor :version
20
20
 
21
+ attr_accessor :debug
22
+
21
23
  def self.cmd_name
22
24
  name.split('::').last.downcase.to_sym
23
25
  end
@@ -106,11 +108,17 @@ module Pik
106
108
 
107
109
  def parse_options
108
110
  options.on("--version", "-V", "Pik version") do |value|
109
- puts "pik " + Pik::VERSION
110
- @version = true
111
+ puts pik_version
112
+ end
113
+ options.on("--debug", "-d", "Outputs debug information") do |value|
114
+ @debug = true
111
115
  end
112
116
  options.parse! @args
113
117
  end
118
+
119
+ def pik_version
120
+ "pik " + Pik::VERSION
121
+ end
114
122
 
115
123
  def current_version?(string)
116
124
  string == get_version
@@ -124,11 +132,6 @@ module Pik
124
132
  "#{major}: #{ruby_ver.strip}"
125
133
  end
126
134
 
127
- # def current_path?(config_path)
128
- # @path ||= SearchPath.new(ENV['PATH'])
129
- # @path.find{|dir| Pathname(dir) == Pathname(config_path) }
130
- # end
131
-
132
135
  def find_config_from_path(path=Which::Ruby.find)
133
136
  config.find{|k,v|
134
137
  Pathname(v[:path])== Pathname(path)
@@ -142,8 +145,16 @@ module Pik
142
145
  end
143
146
 
144
147
  def default_gem_home
145
- path = `#{Which::Ruby.exe} -rubygems -e\"require 'rubygems' ; puts Gem.default_path.first\"`
146
- Pathname.new(path.chomp).to_windows
148
+ get_gem_home(:first)
149
+ end
150
+
151
+ def actual_gem_home
152
+ get_gem_home(:last)
153
+ end
154
+
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
147
158
  end
148
159
 
149
160
  def create(home)
@@ -157,6 +168,11 @@ module Pik
157
168
  end
158
169
  end
159
170
 
171
+ def sh(cmd)
172
+ puts cmd if debug
173
+ system(cmd)
174
+ end
175
+
160
176
  def cmd_name
161
177
  self.class.cmd_name
162
178
  end
@@ -10,9 +10,6 @@ module Pik
10
10
  include BatchFileEditor
11
11
 
12
12
  def execute
13
- unless User.new.admin?
14
- raise "You must have admin rights for the default command"
15
- end
16
13
  sys = WindowsEnv.system
17
14
  usr = WindowsEnv.user
18
15
  new_path = [sys['PATH'],usr['PATH']].compact.join(';')
@@ -1,55 +1,91 @@
1
+
1
2
  module Pik
2
3
 
3
4
  class GemSync < Command
4
5
 
5
- it "Duplicates gems from the current version to the one specified."
6
- include BatchFileEditor
6
+ it "Synchronizes gems from the version specified to the current version."
7
+
8
+ attr_reader :remote, :quiet
7
9
 
8
10
  def execute
9
- target = self.class.choose_from(@args, config)
10
- current = get_version
11
- install_gems(current, target) if target
11
+ source = self.class.choose_from(@args, config)
12
+ raise "Couldn't find a version from the pattern given: '#{@args.join(' ')}'" unless source
13
+ current = find_config_from_path
14
+
15
+ if platform_consistent?(source, current)
16
+ puts "** Syncing: #{current}\n with: #{source}"
17
+ puts " from a remote repository." if remote
18
+ puts
19
+ install_gems(current, source)
20
+ end
12
21
  end
13
22
 
14
- def install_gems(current, target)
15
- switch_path_to(config[target])
16
- switch_gem_home_to(config[target][:gem_home])
17
- target_cache = gem_cache(target)
23
+ def platform_consistent?(source, current)
24
+ s_platform = VersionParser.parse(source).platform
25
+ c_platform = VersionParser.parse(current).platform
26
+ return true if s_platform == c_platform || remote
27
+ msg =<<MSG
28
+ You appear to be attempting a gemsync from a different platform.
29
+
30
+ Sync: #{current}
31
+ with: #{source}
32
+
33
+ If you really want to sync, I recommend you quit and run gemsync with
34
+ the --remote flag.
35
+
36
+ MSG
37
+ raise msg if quiet
38
+ @hl.agree(msg + "Are you sure you'd like to continue?"){|answer| answer.default = 'no'}
39
+ end
40
+
41
+ def install_gems(current, source)
42
+ target_cache = gem_cache(current)
18
43
 
19
- gem_cache(current).find do |file|
44
+ gem_cache(source).find do |file|
20
45
  if file.file?
21
46
  if (target_cache + file.basename).exist?
22
- @batch.echo "Gem #{file.basename} already installed"
47
+ puts "** Gem #{file.basename('.gem')} already installed"
23
48
  else
24
- gem_install(file)
49
+ puts "** Installing #{file.basename('.gem')}"
50
+ gem_opts = "install -q --no-rdoc --no-ri"
51
+ cmd = "#{Which::Gem.exe.basename} #{gem_opts} #{gem_file(file)}"
52
+ puts cmd if debug
53
+ system(cmd)
25
54
  end
26
55
  end
27
56
  end
28
- switch_path_to(config[current])
29
- switch_gem_home_to(config[target][:gem_home])
30
57
  end
31
58
 
32
- def gem_cache(version)
33
- conf = config[version]
34
- path = if conf[:gem_home]
35
- Pathname.new( conf[:gem_home] )
59
+ def gem_file(file)
60
+ if remote
61
+ gem_re = /(.+)\-(\d+\.\d+\.\d+).+/
62
+ file, gem_name, version = file.basename.to_s.match(gem_re).to_a
63
+ "#{gem_name} --version \"=#{version}\" --remote"
36
64
  else
37
- cmd = ruby_exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
38
- Pathname.new( `#{cmd}`.chomp )
65
+ # deal with spaces in path
66
+ file.sub(/.*\s.*/m, '"\&"')
39
67
  end
40
- puts path + "cache"
41
- path + "cache"
42
68
  end
43
69
 
44
- def gem_install(file)
45
- @batch.echo "Installing #{file.basename}"
46
- @batch.call "gem install -q --no-rdoc --no-ri #{file}"
70
+ def gem_cache(version)
71
+ conf = config[version]
72
+ cmd = Which::Ruby.exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
73
+
74
+ path = conf[:gem_home] ? Pathname( conf[:gem_home] ) : Pathname( `#{cmd}`.chomp )
75
+ path + "cache"
47
76
  end
48
77
 
49
78
  def command_options
50
79
  super
51
80
  sep =<<SEP
81
+ Gemsync syncs the current version of ruby with the one given.
82
+
83
+ This tool is fairly dumb. Syncing across implementations is
84
+ probably a bad idea.
85
+
52
86
  Examples:
87
+
88
+ syncs ruby 1.8.6 with the gems install for 1.9.1
53
89
 
54
90
  C:\\>ruby -v
55
91
  ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]
@@ -62,6 +98,13 @@ module Pik
62
98
  ...
63
99
  SEP
64
100
  options.separator sep
101
+
102
+ options.on("--quiet", "-q", "Sync without prompting, fails if platforms don't match") do |value|
103
+ @quiet = value
104
+ end
105
+ options.on("--remote", "-r", "Pull gems from a remote repository") do |value|
106
+ @remote = value
107
+ end
65
108
  end
66
109
 
67
110
  end
@@ -0,0 +1,69 @@
1
+
2
+ module Pik
3
+
4
+ class Info < Command
5
+
6
+ it "Displays information about the current ruby version."
7
+ aka :checkup, :cu
8
+
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)
16
+ current = config[ruby_version]
17
+ gem_home = current[:gem_home] || actual_gem_home
18
+ ruby_version = Pik::VersionParser.parse(ruby_version)
19
+
20
+ return info =<<INFO
21
+ #{pik_version}
22
+
23
+ ruby:
24
+ interpreter: "#{ruby_version.interpreter}"
25
+ version: "#{ruby_version.version}"
26
+ date: "#{ruby_version.date}"
27
+ platform: "#{ruby_version.platform}"
28
+ patchlevel: "#{ruby_version.patchlevel}"
29
+ full_version: "#{ruby_version.full_version}"
30
+
31
+ homes:
32
+ gem: "#{gem_home}"
33
+ ruby: "#{ruby.dirname.dirname}"
34
+
35
+ binaries:
36
+ ruby: "#{ruby}"
37
+ irb: "#{Which::Irb.exe}"
38
+ gem: "#{Which::Gem.exe}"
39
+ rake: "#{Which::Rake.exe}"
40
+
41
+ environment:
42
+ GEM_HOME: "#{ENV['GEM_HOME']}"
43
+ HOME: "#{ENV['HOME']}"
44
+ IRBRC: "#{ENV['IRBRC']}"
45
+ RUBYOPT: "#{ENV['RUBYOPT']}"
46
+
47
+ file associations:
48
+ .rb: #{file_associations('.rb')}
49
+ .rbw: #{file_associations('.rbw')}#{check_path}
50
+ INFO
51
+ end
52
+
53
+ def check_path
54
+ 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")
58
+ end
59
+ end
60
+
61
+ def file_associations(extension)
62
+ @reg = Reg.new
63
+ assoc = @reg.hkcr(extension) rescue nil
64
+ ftype = @reg.hkcr("#{assoc}\\Shell\\open\\command") rescue nil
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -19,7 +19,7 @@ module Pik
19
19
  def execute
20
20
  implementation = Implementations[@args.shift]
21
21
  target, package = implementation.find(*@args)
22
- target = @install_root + "#{implementation.subclass}-#{target.gsub('.','')}"
22
+ target = @install_root + "#{implementation.name}-#{target.gsub('.','')}"
23
23
  file = download(package)
24
24
  extract(target, file)
25
25
  add( Pathname(target) + 'bin' )
@@ -71,6 +71,7 @@ SEP
71
71
  rb = Which::Ruby.exe(path)
72
72
  raise "Unable to find a Ruby executable at #{path}" unless rb
73
73
  puts `"#{rb}" -v `
74
+ puts
74
75
  end
75
76
 
76
77
  def check_args
@@ -150,6 +151,44 @@ SEP
150
151
  end
151
152
 
152
153
  end
154
+
155
+ class Benchmark < Ruby
156
+
157
+ it "Runs bencmarks with all versions that pik is aware of."
158
+ aka :bench
159
+
160
+ def execute
161
+ file_name = @args.first
162
+ file_data = File.read(file_name)
163
+
164
+ Tempfile.open('pik_bench') do |temp|
165
+ @args = [temp.path]
166
+ temp.write benchmark(file_name, file_data)
167
+ end
168
+ super
169
+ end
170
+
171
+ def benchmark(name, data)
172
+ bench =<<BM
173
+ require "benchmark"
174
+ Benchmark.bmbm do |benchmark|
175
+ benchmark.report("** benchmarking '#{File.basename(name)}'") do
176
+ #{data}
177
+ end
178
+ end
179
+ BM
180
+ end
181
+
182
+ def help_message
183
+ sep =<<SEP
184
+ Examples:
185
+
186
+ C:\\>pik benchmark hello.rb
187
+
188
+ SEP
189
+ end
190
+
191
+ end
153
192
 
154
193
  end
155
194
 
@@ -0,0 +1,16 @@
1
+ module Pik
2
+
3
+ class Update < Command
4
+
5
+ aka :up
6
+ it "updates pik."
7
+ include BatchFileEditor
8
+
9
+ def execute
10
+ sh "#{Which::Gem.exe} install pik"
11
+ @batch.call("pik_install #{PIK_BATCH.dirname}")
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -71,6 +71,7 @@ module Pik
71
71
  def subclass
72
72
  self.class.to_s.split('::').last
73
73
  end
74
+ alias :name :subclass
74
75
 
75
76
  end
76
77
 
@@ -0,0 +1,53 @@
1
+ module Pik
2
+
3
+ class VersionParser
4
+
5
+ def self.parse(version)
6
+ new(version)
7
+ end
8
+
9
+ def initialize(version)
10
+ @version = version
11
+ @parts = @version.split(/ |\(|\)/).reject{|i| i.empty? }
12
+ end
13
+
14
+ def interpreter
15
+ @interpreter ||= @parts[1]
16
+ end
17
+
18
+ def version
19
+ md = @parts[2].match(/\d\.\d\.\d\.\d|\d\.\d\.\d/)
20
+ md[0] if md
21
+ end
22
+
23
+ def date
24
+ case interpreter
25
+ when 'IronRuby'
26
+ nil
27
+ when 'ruby', 'jruby'
28
+ md = @version.match(/\d\d\d\d\-\d\d\-\d\d/)
29
+ md[0] if md
30
+ end
31
+ end
32
+
33
+ def platform
34
+ md = @version.match(/\[(.+)\]|(\.NET.+)/)
35
+ md.to_a.compact.last if md
36
+ end
37
+
38
+ def patchlevel
39
+ md = @version.match(/patchlevel (\d+)|\dp(\d+)/)
40
+ md.to_a.compact.last if md
41
+ end
42
+
43
+ def full_version
44
+ @version[5..-1]
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+
52
+
53
+
@@ -9,7 +9,13 @@ module Which
9
9
  path = path.find{|dir| exist?(dir)}
10
10
  Pathname(path) rescue nil
11
11
  end
12
-
12
+
13
+ def find_all(search_path=ENV['PATH'])
14
+ path = SearchPath.new(search_path)
15
+ path = path.find_all{|dir| exist?(dir)}
16
+ path.map{|i| Pathname(i) }
17
+ end
18
+
13
19
  def exist?(path)
14
20
  !!exe(path)
15
21
  end
@@ -54,5 +60,11 @@ module Which
54
60
  ['7za.exe']
55
61
  end
56
62
  end
63
+
64
+ class Irb < Base
65
+ def self.executables
66
+ ['irb.bat', 'ir.exe']
67
+ end
68
+ end
57
69
 
58
70
  end
@@ -5,13 +5,13 @@ require 'Win32API'
5
5
  class WindowsEnv
6
6
 
7
7
  def self.system
8
- key = :HKEY_LOCAL_MACHINE
8
+ key = :HKEY_LOCAL_MACHINE
9
9
  subkey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
10
10
  new(key, subkey)
11
11
  end
12
12
 
13
13
  def self.user
14
- key = :HKEY_CURRENT_USER
14
+ key = :HKEY_CURRENT_USER
15
15
  subkey = 'Environment'
16
16
  new(key, subkey)
17
17
  end
@@ -1,15 +1,7 @@
1
1
  describe Pik::GemSync do
2
2
  it "should have a summary" do
3
- summary = "Duplicates gems from the current version to the one specified."
3
+ summary = "Synchronizes gems from the version specified to the current version."
4
4
  Pik::GemSync.summary.should eql(summary)
5
5
  end
6
6
 
7
- describe "gem_install" do
8
- it "should install gems via batch file" do
9
- gemsync = Pik::GemSync.new([])
10
- gemsync.gem_install(Pathname.new('c:/fake/file.gem'))
11
- gemsync.batch.file_data.should include( "ECHO Installing file.gem" )
12
- gemsync.batch.file_data.should include( "CALL gem install -q --no-rdoc --no-ri c:\\fake\\file.gem\n" )
13
- end
14
- end
15
7
  end
@@ -0,0 +1,121 @@
1
+
2
+ describe Pik::VersionParser do
3
+
4
+ {
5
+ "091: IronRuby 0.9.1.0 on .NET 2.0.0.0" => OpenStruct.new(
6
+ :interpreter => "IronRuby",
7
+ :version => "0.9.1.0",
8
+ :date => nil,
9
+ :platform => ".NET 2.0.0.0",
10
+ :patchlevel => nil,
11
+ :full_version => "IronRuby 0.9.1.0 on .NET 2.0.0.0"
12
+ ),
13
+ "092: IronRuby 0.9.2.0 on .NET 2.0.0.0" => OpenStruct.new(
14
+ :interpreter => "IronRuby",
15
+ :version => "0.9.2.0",
16
+ :date => nil,
17
+ :platform => ".NET 2.0.0.0",
18
+ :patchlevel => nil,
19
+ :full_version => "IronRuby 0.9.2.0 on .NET 2.0.0.0"
20
+ ),
21
+ "131: jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]" => OpenStruct.new(
22
+ :interpreter => "jruby",
23
+ :version => "1.3.1",
24
+ :date => "2009-06-15",
25
+ :platform => "x86-java",
26
+ :patchlevel => "287",
27
+ :full_version => "jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]"
28
+ ),
29
+ "140: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]" => OpenStruct.new(
30
+ :interpreter => "jruby",
31
+ :version => "1.4.0",
32
+ :date => "2009-11-02",
33
+ :platform => "x86-java",
34
+ :patchlevel => "174",
35
+ :full_version => "jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]"
36
+ ),
37
+ "185: ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]" => OpenStruct.new(
38
+ :interpreter => "ruby",
39
+ :version => "1.8.5",
40
+ :date => "2006-12-25",
41
+ :platform => "i386-mswin32",
42
+ :patchlevel => "12",
43
+ :full_version => "ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]"
44
+ ),
45
+ "186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]" => OpenStruct.new(
46
+ :interpreter => "ruby",
47
+ :version => "1.8.6",
48
+ :date => "2008-08-11",
49
+ :platform => "i386-mswin32",
50
+ :patchlevel => "287",
51
+ :full_version => "ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]"
52
+ ),
53
+ "186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]" => OpenStruct.new(
54
+ :interpreter => "ruby",
55
+ :version => "1.8.6",
56
+ :date => "2009-03-31",
57
+ :platform => "i386-mingw32",
58
+ :patchlevel => "368",
59
+ :full_version => "ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]"
60
+ ),
61
+ "186: ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]" => OpenStruct.new(
62
+ :interpreter => "ruby",
63
+ :version => "1.8.6",
64
+ :date => "2009-08-04",
65
+ :platform => "i386-mingw32",
66
+ :patchlevel => "383",
67
+ :full_version => "ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]"
68
+ ),
69
+ "191: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]" => OpenStruct.new(
70
+ :interpreter => "ruby",
71
+ :version => "1.9.1",
72
+ :date => "2009-05-12",
73
+ :platform => "i386-mingw32",
74
+ :patchlevel => "129",
75
+ :full_version => "ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]"
76
+ ),
77
+ "191: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]" => OpenStruct.new(
78
+ :interpreter => "ruby",
79
+ :version => "1.9.1",
80
+ :date => "2009-07-16",
81
+ :platform => "i386-mingw32",
82
+ :patchlevel => "243",
83
+ :full_version => "ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]"
84
+ )
85
+ }.each do |string, data|
86
+
87
+ ruby_version = Pik::VersionParser.parse(string)
88
+
89
+ describe '#parse' do
90
+ it 'should return a VersionParser object' do
91
+ ruby_version.should be_a(Pik::VersionParser)
92
+ end
93
+ end
94
+
95
+ it "should have an interpreter for #{string}" do
96
+ ruby_version.interpreter.should eql(data.interpreter)
97
+ end
98
+
99
+ it "should have a version for #{string}" do
100
+ ruby_version.version.should eql(data.version)
101
+ end
102
+
103
+ it "should have a date for #{string}" do
104
+ ruby_version.date.should eql(data.date)
105
+ end
106
+
107
+ it "should have a platform for #{string}" do
108
+ ruby_version.platform.should eql(data.platform)
109
+ end
110
+
111
+ it "should have a patchlevel for #{string}" do
112
+ ruby_version.patchlevel.should eql(data.patchlevel)
113
+ end
114
+
115
+ it "should have a full_version for #{string}" do
116
+ ruby_version.full_version.should eql(data.full_version)
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -40,4 +40,3 @@ rescue => e
40
40
  ensure
41
41
  cmd.close if cmd
42
42
  end
43
-
Binary file
@@ -8,6 +8,10 @@ file:
8
8
  type: extension-library
9
9
  abbrev.rb:
10
10
  file: c:/ruby/Ruby-186-p383/lib/ruby/1.8/abbrev.rb
11
+ bundler/commands/bundle_command.rb:
12
+ file: c:/ruby/Ruby-186-p383/lib/ruby/gems/1.8/gems/bundler-0.7.0/lib/bundler/commands/bundle_command.rb
13
+ bundler/commands/exec_command.rb:
14
+ file: c:/ruby/Ruby-186-p383/lib/ruby/gems/1.8/gems/bundler-0.7.0/lib/bundler/commands/exec_command.rb
11
15
  cgi.rb:
12
16
  file: c:/ruby/Ruby-186-p383/lib/ruby/1.8/cgi.rb
13
17
  date.rb:
@@ -29,6 +33,8 @@ file:
29
33
  type: extension-library
30
34
  fileutils.rb:
31
35
  file: c:/ruby/Ruby-186-p383/lib/ruby/1.8/fileutils.rb
36
+ find.rb:
37
+ file: c:/ruby/Ruby-186-p383/lib/ruby/1.8/find.rb
32
38
  highline.rb:
33
39
  file: c:/ruby/Ruby-186-p383/lib/ruby/gems/1.8/gems/highline-1.5.1/lib/highline.rb
34
40
  highline/color_scheme.rb:
@@ -105,8 +111,6 @@ file:
105
111
  file: ./../../lib/pik/commands/add_command.rb
106
112
  pik/commands/batch_file_editor.rb:
107
113
  file: ./../../lib/pik/commands/batch_file_editor.rb
108
- pik/commands/checkup_command.rb:
109
- file: ./../../lib/pik/commands/checkup_command.rb
110
114
  pik/commands/command.rb:
111
115
  file: ./../../lib/pik/commands/command.rb
112
116
  pik/commands/config_command.rb:
@@ -121,6 +125,8 @@ file:
121
125
  file: ./../../lib/pik/commands/help_command.rb
122
126
  pik/commands/implode_command.rb:
123
127
  file: ./../../lib/pik/commands/implode_command.rb
128
+ pik/commands/info_command.rb:
129
+ file: ./../../lib/pik/commands/info_command.rb
124
130
  pik/commands/install_command.rb:
125
131
  file: ./../../lib/pik/commands/install_command.rb
126
132
  pik/commands/list_command.rb:
@@ -135,6 +141,8 @@ file:
135
141
  file: ./../../lib/pik/commands/tag_command.rb
136
142
  pik/commands/uninstall_command.rb:
137
143
  file: ./../../lib/pik/commands/uninstall_command.rb
144
+ pik/commands/update_command.rb:
145
+ file: ./../../lib/pik/commands/update_command.rb
138
146
  pik/config_file.rb:
139
147
  file: ./../../lib/pik/config_file.rb
140
148
  pik/contrib/progressbar.rb:
@@ -151,6 +159,8 @@ file:
151
159
  file: ./../../lib/pik/pik.rb
152
160
  pik/search_path.rb:
153
161
  file: ./../../lib/pik/search_path.rb
162
+ pik/version_parser.rb:
163
+ file: ./../../lib/pik/version_parser.rb
154
164
  pik/which.rb:
155
165
  file: ./../../lib/pik/which.rb
156
166
  pik/windows_env.rb:
@@ -168,6 +178,10 @@ file:
168
178
  file: c:/ruby/Ruby-186-p383/lib/ruby/site_ruby/1.8/rubygems.rb
169
179
  rubygems/builder.rb:
170
180
  file: c:/ruby/Ruby-186-p383/lib/ruby/site_ruby/1.8/rubygems/builder.rb
181
+ rubygems/command.rb:
182
+ file: c:/ruby/Ruby-186-p383/lib/ruby/site_ruby/1.8/rubygems/command.rb
183
+ rubygems/command_manager.rb:
184
+ file: c:/ruby/Ruby-186-p383/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb
171
185
  rubygems/config_file.rb:
172
186
  file: c:/ruby/Ruby-186-p383/lib/ruby/site_ruby/1.8/rubygems/config_file.rb
173
187
  rubygems/custom_require.rb:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gordon Thiesfeld
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 -06:00
12
+ date: 2009-11-08 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,21 +33,33 @@ dependencies:
33
33
  version: 2.3.3
34
34
  version:
35
35
  description: |-
36
- Pik is a tool to switch between multiple versions of ruby on Windows.
36
+ Pik is a tool to manage multiple versions of ruby on Windows.
37
37
 
38
- Or to put it another way
39
-
40
- doskey rvm=pik $* # (sort of)
41
-
42
- You have to tell it where your different ruby versions live using
43
- 'pik add'. Then you can change to one by using 'pik switch'.
44
-
45
- It also supports running commands/code with all versions configured.
46
-
47
- pik run # Runs commands on the command line
48
- pik ruby # Runs using the ruby interpreter for each version (ruby.exe, jruby.bat, ir.exe)
49
- pik gem # Runs using the gem command for each version (gem.bat, igem.bat)
50
- pik rake # Runs using the rake command for each version (rake.bat, irake.bat)
38
+ >pik help commands
39
+
40
+ add Adds another ruby location to pik.
41
+ benchmark|bench Runs bencmarks with all versions that pik is aware of.
42
+ checkup|cu Checks your environment for current Ruby best practices.
43
+ config Adds/modifies configuration options.
44
+ default Switches back to the default settings.
45
+ gem Runs the gem command with all versions that pik is aware of.
46
+ gemsync Synchronizes gems from the version specified to the current version.
47
+ help Displays help information.
48
+ implode Removes your pik configuration.
49
+ info Displays information about the current ruby version.
50
+ install|in Downloads and installs different ruby versions.
51
+ list|ls Lists ruby versions that pik is aware of.
52
+ rake Runs the rake command with all versions that pik is aware of.
53
+ remove|rm Removes a ruby location from pik.
54
+ ruby|rb Runs ruby with all versions that pik is aware of.
55
+ run Runs command with all versions of ruby that pik is aware of.
56
+ switch|sw|use Switches ruby versions based on patterns.
57
+ tag Adds the given tag to the current version.
58
+ tags Runs the pik command against the given tags.
59
+ uninstall|unin Deletes a ruby version from the filesystem and removes it from Pik.
60
+ update|up updates pik.
61
+
62
+ For help on a particular command, use 'pik help COMMAND'.
51
63
  email:
52
64
  - gthiesfeld@gmail.com
53
65
  executables:
@@ -82,11 +94,9 @@ files:
82
94
  - features/version.feature
83
95
  - lib/pik.rb
84
96
  - lib/pik/batch_file.rb
85
- - lib/pik/checkup.rb
86
97
  - lib/pik/commands.rb
87
98
  - lib/pik/commands/add_command.rb
88
99
  - lib/pik/commands/batch_file_editor.rb
89
- - lib/pik/commands/checkup_command.rb
90
100
  - lib/pik/commands/command.rb
91
101
  - lib/pik/commands/config_command.rb
92
102
  - lib/pik/commands/config_file_editor.rb
@@ -94,6 +104,7 @@ files:
94
104
  - lib/pik/commands/gemsync_command.rb
95
105
  - lib/pik/commands/help_command.rb
96
106
  - lib/pik/commands/implode_command.rb
107
+ - lib/pik/commands/info_command.rb
97
108
  - lib/pik/commands/install_command.rb
98
109
  - lib/pik/commands/list_command.rb
99
110
  - lib/pik/commands/remove_command.rb
@@ -101,6 +112,7 @@ files:
101
112
  - lib/pik/commands/switch_command.rb
102
113
  - lib/pik/commands/tag_command.rb
103
114
  - lib/pik/commands/uninstall_command.rb
115
+ - lib/pik/commands/update_command.rb
104
116
  - lib/pik/config_file.rb
105
117
  - lib/pik/contrib/progressbar.rb
106
118
  - lib/pik/contrib/unzip.rb
@@ -116,6 +128,7 @@ files:
116
128
  - lib/pik/options.rb
117
129
  - lib/pik/pik.rb
118
130
  - lib/pik/search_path.rb
131
+ - lib/pik/version_parser.rb
119
132
  - lib/pik/which.rb
120
133
  - lib/pik/windows_env.rb
121
134
  - spec/add_command_spec.rb
@@ -136,6 +149,7 @@ files:
136
149
  - spec/search_path_spec.rb
137
150
  - spec/spec.opts
138
151
  - spec/switch_command_spec.rb
152
+ - spec/version_parser_spec.rb
139
153
  - spec/which_spec.rb
140
154
  - tools/pik.bat
141
155
  - tools/pik/pik_runner
@@ -200,6 +214,6 @@ rubyforge_project: pik
200
214
  rubygems_version: 1.3.5
201
215
  signing_key:
202
216
  specification_version: 3
203
- summary: Pik is a tool to switch between multiple versions of ruby on Windows
217
+ summary: Pik is a tool to manage multiple versions of ruby on Windows
204
218
  test_files: []
205
219
 
@@ -1,11 +0,0 @@
1
- # class Pik
2
-
3
- # class Checkup
4
-
5
- # def initialize(text)
6
- # @text = text
7
- # @output = ["Checkup results:"]
8
- # end
9
-
10
-
11
- # end
@@ -1,70 +0,0 @@
1
- module Pik
2
-
3
- class Checkup < Command
4
-
5
- aka :cu
6
- it "Checks your environment for current Ruby best practices."
7
-
8
- def execute
9
- home
10
- rubyopt
11
- path
12
- pathext
13
- end
14
-
15
- def to_s
16
- ERB.new(@output.join("\n\n")).result
17
- end
18
-
19
- def rubyopt
20
- unless WindowsEnv.user['rubyopt'].nil? && WindowsEnv.system['rubyopt'].nil?
21
- fail('rubyopt')
22
- else
23
- pass('rubyopt')
24
- end
25
- end
26
-
27
- def home
28
- if WindowsEnv.user['home'].empty?
29
- fail('home')
30
- else
31
- pass('home')
32
- end
33
- end
34
-
35
- def path
36
- user_path = WindowsEnv.user['path'] || ''
37
- syst_path = WindowsEnv.system['path'] || ''
38
- dirs = (user_path + syst_path).split(';')
39
- dirs = dirs.select{|dir| File.exist?( File.join(dir,'ruby.exe') ) }
40
- unless dirs.size == 1
41
- fail('path')
42
- else
43
- pass('path')
44
- end
45
- end
46
-
47
- def pathext
48
- p_ext = WindowsEnv.system['pathext'].downcase
49
- unless p_ext.include?('.rb') && p_ext.include?('.rbw')
50
- fail('pathext')
51
- else
52
- pass('pathext')
53
- end
54
- end
55
-
56
- def pass(test)
57
- print '.'
58
- $stdout.flush
59
- # @output << @text[test][:pass]
60
- end
61
-
62
- def fail(test)
63
- print 'F'
64
- $stdout.flush
65
- # @output << @text[test][:fail]
66
- end
67
-
68
- end
69
-
70
- end