Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

default is now uses alias, instead of a separate command

  • Loading branch information...
commit 8bffe79c4e8237102ededc4ae294f130ff6486a0 1 parent c173acd
@vertiginous authored
View
2  Manifest.txt
@@ -31,8 +31,6 @@ lib/pik/commands/add_command.rb
lib/pik/commands/alias_command.rb
lib/pik/commands/command.rb
lib/pik/commands/config_file_editor.rb
-lib/pik/commands/default_command.rb
-lib/pik/commands/gemsync_command.rb
lib/pik/commands/help_command.rb
lib/pik/commands/implode_command.rb
lib/pik/commands/info_command.rb
View
1  lib/pik.rb
@@ -29,7 +29,6 @@
require 'pik/commands/run_command'
require 'pik/commands/refresh_command'
require 'pik/commands/remove_command'
-require 'pik/commands/default_command'
require 'pik/commands/implode_command'
require 'pik/commands/system_command'
require 'pik/commands/uninstall_command'
View
25 lib/pik/commands/default_command.rb
@@ -1,25 +0,0 @@
-
-module Pik
-
- class Default < Command
-
- it "Switches to the default ruby."
-
- attr_accessor :verbose
-
- def execute
- if ruby = config.match(config.global[:default])
- config.options[:use] = ruby
- use = Pik::Use.new([], config)
- use.execute
- use.close
- else
- msg = "Error: You must define a default ruby first. Run:\n\n"
- msg << " pik use [ruby] --default\n\n"
- abort msg
- end
- end
-
- end
-
-end
View
114 lib/pik/commands/gemsync_command.rb
@@ -1,114 +0,0 @@
-
-module Pik
-
- class GemSync < Command
-
- it "Synchronizes gems from the version specified to the current version."
-
- attr_reader :remote, :quiet
-
- def execute
- source = @config.match(@args.first)
- raise "Couldn't find a version from the pattern given: '#{@args.join(' ')}'" unless source
- current = find_config_from_path
-
- if platform_consistent?(source, current)
- puts "** Syncing: #{current}\n with: #{source}"
- puts " from a remote repository." if remote
- puts
- install_gems(current, source)
- end
- end
-
- def platform_consistent?(source, current)
- s_platform = VersionParser.parse(source).platform
- c_platform = VersionParser.parse(current).platform
- return true if s_platform == c_platform || remote
- msg =<<MSG
- You appear to be attempting a gemsync from a different platform.
-
- Sync: #{current}
- with: #{source}
-
- If you really want to sync, I recommend you quit and run gemsync with
- the --remote flag.
-
-MSG
- raise msg if quiet
- @hl.agree(msg + "Are you sure you'd like to continue?"){|answer| answer.default = 'no'}
- end
-
- def install_gems(current, source)
- target_cache = gem_cache(current)
-
- gem_cache(source).find do |file|
- if file.file?
- if (target_cache + file.basename).exist?
- puts "** Gem #{file.basename('.gem')} already installed"
- else
- puts "** Installing #{file.basename('.gem')}"
- gem_opts = "install -q --no-rdoc --no-ri"
- cmd = "#{Which::Gem.exe.basename} #{gem_opts} #{gem_file(file)}"
- puts cmd if debug
- system(cmd)
- end
- end
- end
- end
-
- def gem_file(file)
- if remote
- gem_re = /(.+)\-(\d+\.\d+\.\d+).+/
- file, gem_name, version = file.basename.to_s.match(gem_re).to_a
- "#{gem_name} --version \"=#{version}\" --remote"
- else
- # deal with spaces in path
- file.sub(/.*\s.*/m, '"\&"')
- end
- end
-
- def gem_cache(version)
- conf = config[version]
- cmd = Which::Ruby.exe(conf[:path]).to_s + " -rubygems -e \"puts Gem.default_path.last\""
-
- path = conf[:gem_home] ? Pathname( conf[:gem_home] ) : Pathname( `#{cmd}`.chomp )
- cache = path + "cache"
- puts "cache: #{cache}" if debug
- cache
- end
-
- def command_options
- super
- sep =<<SEP
- Gemsync syncs the current version of ruby with the one given.
-
- This tool is fairly dumb. Syncing across implementations is
- probably a bad idea.
-
- Examples:
-
- syncs ruby 1.8.6 with the gems install for 1.9.1
-
- C:\\>ruby -v
- ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mingw32]
-
- C:\\>pik gemsync 191 p2
- Gem ZenTest-4.1.4.gem already installed
- Installing xml-simple-1.0.12.gem
- Successfully installed xml-simple-1.0.12
- 1 gem installed
- ...
-SEP
- options.separator sep
-
- options.on("--quiet", "-q", "Sync without prompting, fails if platforms don't match") do |value|
- @quiet = value
- end
- options.on("--remote", "-r", "Pull gems from a remote repository") do |value|
- @remote = value
- end
- end
-
- end
-
-end
View
4 lib/pik/commands/help_command.rb
@@ -13,6 +13,10 @@ def execute
Commands.find(a).description
when :commands
Commands.description
+ when :default
+ msg = "Error: You must define a default ruby first.\n\nRun:\n\n"
+ msg << " pik use [ruby] --default\n\n"
+ abort msg
else
"There is no command '#{a}' \n" +
Pik::Help.description
View
8 lib/pik/commands/list_command.rb
@@ -34,15 +34,13 @@ def remote_list
end
def default_list(type=:simple)
- puts "Default Ruby\n\n"
- if default = config.match(config.global[:default])
+ if default = config.find_alias('default')
+ puts "Default Ruby\n\n"
name, config = *default
name = VersionPattern.full(name) if type == :simple
puts layout(name, config)
else
- puts "no default assigned."
- puts "run 'pik use [ruby] --default' to assign one"
- puts
+ Pik::Help.new(['default']).execute
end
end
View
2  lib/pik/commands/use_command.rb
@@ -16,7 +16,7 @@ def execute
ver_name, ver_config = *new_ver
- config.global[:default] = VersionPattern.full(ver_name) if default
+ ver_config[:alias] = 'default' if default
switch_path_to(ver_config)
switch_gem_home_to(ver_config[:gem_home])
Please sign in to comment.
Something went wrong with that request. Please try again.