pik 0.1.0

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 (43) hide show
  1. data/History.txt +36 -0
  2. data/Manifest.txt +42 -0
  3. data/README.rdoc +174 -0
  4. data/Rakefile +37 -0
  5. data/bin/pik +33 -0
  6. data/lib/pik.rb +30 -0
  7. data/lib/pik/batch_file.rb +70 -0
  8. data/lib/pik/checkup.rb +11 -0
  9. data/lib/pik/commands.rb +35 -0
  10. data/lib/pik/commands/add_command.rb +65 -0
  11. data/lib/pik/commands/batch_file_editor.rb +62 -0
  12. data/lib/pik/commands/checkup_command.rb +67 -0
  13. data/lib/pik/commands/command.rb +166 -0
  14. data/lib/pik/commands/config_command.rb +28 -0
  15. data/lib/pik/commands/config_file_editor.rb +12 -0
  16. data/lib/pik/commands/default_command.rb +22 -0
  17. data/lib/pik/commands/gemsync_command.rb +69 -0
  18. data/lib/pik/commands/help_command.rb +44 -0
  19. data/lib/pik/commands/implode_command.rb +16 -0
  20. data/lib/pik/commands/list_command.rb +34 -0
  21. data/lib/pik/commands/remove_command.rb +29 -0
  22. data/lib/pik/commands/run_command.rb +37 -0
  23. data/lib/pik/commands/switch_command.rb +49 -0
  24. data/lib/pik/config_file.rb +21 -0
  25. data/lib/pik/core_ext/pathname.rb +15 -0
  26. data/lib/pik/options.rb +56 -0
  27. data/lib/pik/runner.rb +16 -0
  28. data/lib/pik/search_path.rb +51 -0
  29. data/lib/pik/windows_env.rb +64 -0
  30. data/spec/add_command_spec.rb +15 -0
  31. data/spec/batch_file_spec.rb +31 -0
  32. data/spec/command_spec.rb +34 -0
  33. data/spec/commands_spec.rb +44 -0
  34. data/spec/default_command_spec.rb +6 -0
  35. data/spec/gemsync_command_spec.rb +15 -0
  36. data/spec/help_command_spec.rb +30 -0
  37. data/spec/list_command_spec.rb +33 -0
  38. data/spec/remove_command_spec.rb +25 -0
  39. data/spec/run_command_spec.rb +36 -0
  40. data/spec/search_path_spec.rb +121 -0
  41. data/spec/spec.opts +3 -0
  42. data/spec/switch_command_spec.rb +44 -0
  43. metadata +143 -0
@@ -0,0 +1,36 @@
1
+ === 0.1.0 / 2009-09-24
2
+
3
+ * removed jruby support for the time being (lack of win32ole is a problem)
4
+ * added more helpful messages to pik add
5
+ * renamed gemdup to gemsync. fixed the code up a bit
6
+ * added default and implode commands, shortcuts for switch, more specs, lots of refactors
7
+ * removed add_gem_home command. GEM_HOME can be configured with pik config
8
+ * change remove 'force' to 'quiet'
9
+ * added simpler switch semantics (`pik 191 p243` instead of `pik switch 191 p243`)
10
+ * added gemdup command
11
+ * option parsing is now done with optparse and not a regex
12
+ * rewrote pik to use classes for each command in the hopes that my code would be easier to read
13
+ * Added post install instructions - issue 5. Switched to Hoe.spec for Hoe compatibility. added Hoe-git plugin.
14
+ * added verbose output and current version specifier to 'list'
15
+ * added 'use' as an alias for 'switch'
16
+ * cleaner method of remvoving .pik/pik batch file, fixed some long lines
17
+
18
+ === 0.0.3 / 2009-06-10
19
+
20
+ * added 'add_gem_home' command
21
+ due to changes in the config, you'll have to delete your "%HOME%\.pik\config.yml" and recreate it.
22
+ * don't use GEM_HOME on XP with rubygems 1.3.4, wait for 1.3.5, or point them to a path without spaces.
23
+
24
+ === 0.0.2 / 2009-06-02
25
+
26
+ * several minor enhancements
27
+ *updated help messages
28
+ *updated readme
29
+ *some formatting of output
30
+
31
+ === 0.0.1 / 2009-06-02
32
+
33
+ * 1 major enhancement
34
+
35
+ * Birthday!
36
+
@@ -0,0 +1,42 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/pik
6
+ lib/pik.rb
7
+ lib/pik/batch_file.rb
8
+ lib/pik/checkup.rb
9
+ lib/pik/commands.rb
10
+ lib/pik/commands/add_command.rb
11
+ lib/pik/commands/batch_file_editor.rb
12
+ lib/pik/commands/checkup_command.rb
13
+ lib/pik/commands/command.rb
14
+ lib/pik/commands/config_command.rb
15
+ lib/pik/commands/config_file_editor.rb
16
+ lib/pik/commands/default_command.rb
17
+ lib/pik/commands/gemsync_command.rb
18
+ lib/pik/commands/help_command.rb
19
+ lib/pik/commands/implode_command.rb
20
+ lib/pik/commands/list_command.rb
21
+ lib/pik/commands/remove_command.rb
22
+ lib/pik/commands/run_command.rb
23
+ lib/pik/commands/switch_command.rb
24
+ lib/pik/config_file.rb
25
+ lib/pik/core_ext/pathname.rb
26
+ lib/pik/options.rb
27
+ lib/pik/runner.rb
28
+ lib/pik/search_path.rb
29
+ lib/pik/windows_env.rb
30
+ spec/add_command_spec.rb
31
+ spec/batch_file_spec.rb
32
+ spec/command_spec.rb
33
+ spec/commands_spec.rb
34
+ spec/default_command_spec.rb
35
+ spec/gemsync_command_spec.rb
36
+ spec/help_command_spec.rb
37
+ spec/list_command_spec.rb
38
+ spec/remove_command_spec.rb
39
+ spec/run_command_spec.rb
40
+ spec/search_path_spec.rb
41
+ spec/spec.opts
42
+ spec/switch_command_spec.rb
@@ -0,0 +1,174 @@
1
+ = pik
2
+
3
+ http://github.com/vertiginous/pik
4
+
5
+ Gordon Thiesfeld
6
+
7
+ == DESCRIPTION:
8
+
9
+ Pik is a tool to switch between multiple versions of ruby on Windows.
10
+
11
+ Or to put it another way
12
+
13
+ doskey rvm=pik $* # (sort of)
14
+
15
+ You have to tell it where your different ruby versions live using
16
+ 'pik add'. Then you can change to one by using 'pik switch'.
17
+
18
+ It also has a "sort of" multiruby functionality in 'pik run'.
19
+
20
+
21
+ == FEATURES/PROBLEMS:
22
+
23
+ Changes are to the open cmd session only.
24
+
25
+ Only works on MRI at present, support for JRuby, and maybe IronRuby are planned.
26
+
27
+ == SYNOPSIS:
28
+
29
+ C:\>pik help commands
30
+
31
+ add Adds another ruby location to pik.
32
+ checkup|cu Checks your environment for current Ruby best practices.
33
+ config Adds/modifies configuration options.
34
+ default switches back to the default settings
35
+ gemsync Duplicates gems from the current version to the one specified.
36
+ help Displays help information.
37
+ implode Removes your pik configuration.
38
+ list|ls Lists ruby versions that pik is aware of.
39
+ remove|rm Removes a ruby location from pik.
40
+ run Runs command with all version of ruby that pik is aware of.
41
+ switch|sw|use Switches ruby versions based on patterns.
42
+
43
+ For help on a particular command, use 'pik help COMMAND'.
44
+
45
+ == REQUIREMENTS:
46
+
47
+ Windows, more than one version of Ruby (otherwise, what's the point?) and Rubygems
48
+
49
+ == INSTALL:
50
+
51
+ 1. gem install pik
52
+ 2. pik add # adds your current ruby's bin dir
53
+ 3. pik add path\to\some\other\ruby\bin # for another version
54
+ 4. repeat step 3 for each version of ruby you have, or use 'pik add -i' for super-fancy interactive mode!
55
+ 5. pik run "gem install vertiginous-pik"
56
+
57
+
58
+
59
+ == EXAMPLES:
60
+
61
+ pik add
62
+
63
+ C:\>ruby -v
64
+ ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]
65
+
66
+ C:\>pik add
67
+ Adding: 186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]'
68
+ Located at: c:/ruby/186-p368-mingw32/bin
69
+
70
+ C:\>pik add C:\ruby\191-p243-mingw32\bin
71
+ Adding: 191: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]'
72
+ Located at: C:/ruby/191-p243-mingw32/bin
73
+
74
+ pik list
75
+
76
+ C:\>pik list
77
+ 185: ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]
78
+ 186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
79
+ 186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32] *
80
+ 191: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]
81
+ 191: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]
82
+
83
+ or
84
+
85
+ C:\>pik list -v
86
+ 185: ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]
87
+ path: C:/ruby/185-p012-mswin32/bin
88
+
89
+ 186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
90
+ path: C:/ruby/186-p287-mswin32/bin
91
+
92
+ 186: ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32] *
93
+ path: C:/ruby/186-p368-mingw32/bin
94
+
95
+ 191: ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]
96
+ path: C:/ruby/191-p129-mingw32/bin
97
+
98
+ 191: ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]
99
+ path: C:/ruby/191-p243-mingw32/bin
100
+
101
+ pik switch
102
+
103
+ C:\>pik switch 191 p129
104
+ == Switching to ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32] ==
105
+
106
+ or
107
+
108
+ C:\>pik sw 185
109
+ == Switching to ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32] ==
110
+
111
+ or
112
+
113
+ C:\>pik use 186 ms
114
+ == Switching to ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] ==
115
+
116
+ or
117
+
118
+ C:\>pik 191 p2
119
+ == Switching to ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] ==
120
+
121
+ or
122
+
123
+ C:\>pik default
124
+ == Switching to ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32] ==
125
+
126
+ pik run
127
+
128
+ C:\>pik run "gem in hpricot"
129
+ == Running with ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32] ==
130
+ Successfully installed hpricot-0.8.1-x86-mswin32
131
+ 1 gem installed
132
+
133
+ == Running with ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] ==
134
+ Successfully installed hpricot-0.8.1-x86-mswin32
135
+ 1 gem installed
136
+
137
+ == Running with ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32] ==
138
+ Building native extensions. This could take a while...
139
+ Successfully installed hpricot-0.8.1
140
+ 1 gem installed
141
+
142
+ == Running with ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32] ==
143
+ Building native extensions. This could take a while...
144
+ Successfully installed hpricot-0.8.1
145
+ 1 gem installed
146
+
147
+ == Running with ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] ==
148
+ Successfully installed hpricot-0.8.1
149
+ 1 gem installed
150
+
151
+ == LICENSE:
152
+
153
+ (The MIT License)
154
+
155
+ Copyright (c) 2009 Gordon Thiesfeld
156
+
157
+ Permission is hereby granted, free of charge, to any person obtaining
158
+ a copy of this software and associated documentation files (the
159
+ 'Software'), to deal in the Software without restriction, including
160
+ without limitation the rights to use, copy, modify, merge, publish,
161
+ distribute, sublicense, and/or sell copies of the Software, and to
162
+ permit persons to whom the Software is furnished to do so, subject to
163
+ the following conditions:
164
+
165
+ The above copyright notice and this permission notice shall be
166
+ included in all copies or substantial portions of the Software.
167
+
168
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
169
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
170
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
171
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
172
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
173
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
174
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ $LOAD_PATH.unshift('lib')
7
+ require 'pik'
8
+
9
+ Hoe.plugin :git
10
+
11
+ Hoe.spec('pik') do
12
+
13
+ developer('Gordon Thiesfeld', 'gthiesfeld@gmail.com')
14
+
15
+ self.extra_deps = {'highline' => '>= 0.0.0'}
16
+ self.readme_file = 'README.rdoc'
17
+ self.post_install_message =<<-PIM
18
+
19
+ ----------------------------------------------------------------------------
20
+
21
+ 1. Use 'pik add' to add all versions of ruby to your pik config,
22
+ or use 'pik add -i' for an interactive console to do the same.
23
+ The current ruby version is added by default.
24
+
25
+ see 'pik help add' for more info
26
+
27
+ 2. Run 'pik run "gem install pik"' to install pik to all Ruby versions.
28
+
29
+ 3. Run 'pik help' for help.
30
+
31
+ ----------------------------------------------------------------------------
32
+
33
+ PIM
34
+
35
+ end
36
+
37
+ # vim: syntax=Ruby
data/bin/pik ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'pik')
3
+
4
+ include Pik
5
+
6
+ args = ARGV
7
+
8
+ Command.clean_gem_batch
9
+
10
+ begin
11
+ config = ConfigFile.new
12
+
13
+ args << 'help' if args.empty?
14
+
15
+ command = if Command.choose_from(args, config)
16
+ Switch
17
+ elsif (cmd = Commands.find(args.shift))
18
+ cmd
19
+ else
20
+ Help
21
+ end
22
+
23
+ cmd = command.new(args, config)
24
+ cmd.execute
25
+ rescue QuitError
26
+ puts "\nQuitting..."
27
+ rescue => e
28
+ puts "\nThere was an error"
29
+ puts " Error: #{e.message}\n\n"
30
+ puts e.backtrace
31
+ ensure
32
+ cmd.close if cmd
33
+ end
@@ -0,0 +1,30 @@
1
+ module Pik
2
+ VERSION = '0.1.0'
3
+ end
4
+
5
+ require 'highline'
6
+ require 'pathname'
7
+ require 'rbconfig'
8
+
9
+ require 'pik/core_ext/pathname'
10
+ require 'pik/commands'
11
+ require 'pik/commands/config_file_editor'
12
+ require 'pik/commands/batch_file_editor'
13
+ require 'pik/commands/command'
14
+ require 'pik/commands/list_command'
15
+ require 'pik/commands/add_command'
16
+ require 'pik/commands/help_command'
17
+ require 'pik/commands/switch_command'
18
+ require 'pik/commands/run_command'
19
+ require 'pik/commands/remove_command'
20
+ require 'pik/commands/checkup_command'
21
+ require 'pik/commands/config_command'
22
+ require 'pik/commands/gemsync_command'
23
+ require 'pik/commands/default_command'
24
+ require 'pik/commands/implode_command'
25
+ require 'pik/config_file'
26
+ require 'pik/windows_env'
27
+ require 'pik/batch_file'
28
+ require 'pik/search_path'
29
+
30
+ PIK_HOME = Pathname.new( ENV['HOME'] || ENV['USERPROFILE'] ) + '.pik'
@@ -0,0 +1,70 @@
1
+
2
+ class BatchFile
3
+
4
+ def self.open(file)
5
+ bf = new(file, :open)
6
+ yield bf if block_given?
7
+ bf
8
+ end
9
+
10
+ attr_accessor :file_data, :file_name, :ruby_dir
11
+
12
+ def initialize(file, mode=:new)
13
+ @rubyw_exe = 'rubyw.exe'
14
+ @ruby_exe = 'ruby.exe'
15
+ @file = Pathname.new(file)
16
+ case mode
17
+ when :open
18
+ @file_data = File.read(@file).split("\n")
19
+ when :new
20
+ @file_data = [header]
21
+ end
22
+ yield self if block_given?
23
+ end
24
+
25
+ def path
26
+ @file
27
+ end
28
+
29
+ def header
30
+ string = "@ECHO OFF\n\n"
31
+ string << ":: This batch file generated by Pik, the\n"
32
+ string << ":: Ruby Manager for Windows\n"
33
+ end
34
+
35
+ def ftype(files={ 'rbfile' => @ruby_exe, 'rbwfile' => @rubyw_exe })
36
+ files.sort.each do |filetype, open_with|
37
+ @file_data << "FTYPE #{filetype}=#{open_with} \"%1\" %*\n"
38
+ end
39
+ self
40
+ end
41
+
42
+ def call(bat)
43
+ @file_data << "CALL #{bat}\n"
44
+ self
45
+ end
46
+
47
+ def set(items)
48
+ items.each{|k,v| @file_data << "SET #{k}=#{v}" }
49
+ self
50
+ end
51
+
52
+ def echo(string)
53
+ string = ' ' + string unless string == '.'
54
+ @file_data << "ECHO#{string}"
55
+ self
56
+ end
57
+
58
+ def remove_line(re)
59
+ @file_data.reject!{ |i| i =~ re }
60
+ end
61
+
62
+ def to_s
63
+ @file_data.join("\n")
64
+ end
65
+
66
+ def write
67
+ File.open(@file, 'w+'){|f| f.puts self.to_s }
68
+ end
69
+
70
+ end
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,35 @@
1
+ module Pik
2
+
3
+ module Commands
4
+
5
+ def self.clear
6
+ commands.clear
7
+ end
8
+
9
+ def self.add(command)
10
+ commands << command
11
+ end
12
+
13
+ def self.find(command)
14
+ commands.find{ |cmd| cmd.names.include?(command.to_sym) }
15
+ end
16
+
17
+ def self.list
18
+ commands.map{|c| c.names }.flatten
19
+ end
20
+
21
+ def self.description
22
+ commands.sort_by{|c| c.name }.map do |cmd|
23
+ " %-15s %s" % [cmd.names.join('|'), cmd.summary]
24
+ end.join("\n") +
25
+ "\n\nFor help on a particular command, use 'pik help COMMAND'."
26
+ end
27
+
28
+ def self.commands
29
+ @commands ||= []
30
+ end
31
+
32
+
33
+ end
34
+
35
+ end