Skip to content

Commit

Permalink
the BIG REWRITE is underway
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 4, 2009
1 parent 9a417bc commit 341fbd1
Show file tree
Hide file tree
Showing 38 changed files with 1,118 additions and 598 deletions.
46 changes: 23 additions & 23 deletions .autotest
@@ -1,23 +1,23 @@
# -*- ruby -*-

require 'autotest/restart'

# Autotest.add_hook :initialize do |at|
# at.extra_files << "../some/external/dependency.rb"
#
# at.libs << ":../some/external"
#
# at.add_exception 'vendor'
#
# at.add_mapping(/dependency.rb/) do |f, _|
# at.files_matching(/test_.*rb$/)
# end
#
# %w(TestA TestB).each do |klass|
# at.extra_class_map[klass] = "test/test_misc.rb"
# end
# end

# Autotest.add_hook :run_command do |at|
# system "rake build"
# end
# -*- ruby -*-
require 'win32console'
require 'autotest/restart'

Autotest.add_hook :initialize do |at|
# at.extra_files << "../some/external/dependency.rb"

# at.libs << ":../some/external"

at.add_exception 'bin'

# at.add_mapping(/dependency.rb/) do |f, _|
# at.files_matching(/test_.*rb$/)
# end

# %w(TestA TestB).each do |klass|
# at.extra_class_map[klass] = "test/test_misc.rb"
# end
end

# Autotest.add_hook :run_command do |at|
# system "rake build"
# end
32 changes: 19 additions & 13 deletions History.txt
@@ -1,13 +1,19 @@
=== 0.0.2 / 2009-06-02

* several minor enhancements
*updated help messages
*updated readme
*some formatting of output

=== 0.0.1 / 2009-06-02

* 1 major enhancement

* Birthday!

=== 0.0.3 / 2009-06-10

* added 'add_gem_home' command
due to changes in the config, you'll have to delete your "%HOME%\.pik\config.yml" and recreate it.
* 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.

=== 0.0.2 / 2009-06-02

* several minor enhancements
*updated help messages
*updated readme
*some formatting of output

=== 0.0.1 / 2009-06-02

* 1 major enhancement

* Birthday!

50 changes: 30 additions & 20 deletions bin/pik
@@ -1,20 +1,30 @@
#!/usr/bin/env ruby

# pik switch 186
# pik switch 186 mingw
# pik switch 191 --system

# pik config default=186 mingw
# pik config home
# pik config rubyopt=(on|off)

# pik checkup

# pik search
# pik add (path_to_ruby)
# pik help (command)


require File.join(File.dirname(__FILE__), '..', 'lib', 'pik')

Pik::Runner.execute
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '..', 'lib', 'pik')

include Pik

args = ARGV
cmd = args.shift || 'help'
cmd = cmd.downcase.to_sym

Command.clean_gem_batch

begin
config = ConfigFile.new
command = Commands.find(cmd)
command ||= if args = [Command.choose_from(ARGV.unshift(cmd), config)]
Switch
else
Help
end
cmd = command.new(args, config)
cmd.execute
rescue QuitError
puts "\nQuitting..."
rescue => e
puts "\nThere was an error"
puts " Error: #{e.message}\n\n"
puts e.backtrace
ensure
cmd.close if cmd
end
31 changes: 19 additions & 12 deletions lib/pik.rb
@@ -1,22 +1,29 @@
class Pik
module Pik
VERSION = '0.0.3'
end

$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'erb'
require 'highline'
require 'fileutils'
require 'pathname'
require 'rbconfig'

require 'pik/runner'
require 'pik/config'
require 'pik/checkup'
require 'pik/windows_file'
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'pik/core_ext/pathname'
require 'pik/commands'
require 'pik/commands/config_file_editor'
require 'pik/commands/batch_file_editor'
require 'pik/commands/command'
require 'pik/commands/list_command'
require 'pik/commands/add_command'
require 'pik/commands/help_command'
require 'pik/commands/switch_command'
require 'pik/commands/run_command'
require 'pik/commands/remove_command'
require 'pik/commands/checkup_command'
require 'pik/commands/config_command'
require 'pik/commands/gemdup_command'
require 'pik/config_file'
require 'pik/windows_env'
require 'pik/batch_file'
require 'pik/search_path'

PIK_HOME = File.join( (ENV['HOME'] || ENV['USERPROFILE']) , '.pik')


PIK_HOME = Pathname.new( ENV['HOME'] || ENV['USERPROFILE'] ) + '.pik'
30 changes: 11 additions & 19 deletions lib/pik/batch_file.rb
@@ -1,31 +1,29 @@

class BatchFile

def self.open(file_name)
bf = new(file_name, :open)
def self.open(file)
bf = new(file, :open)
yield bf if block_given?
bf
end

attr_accessor :file_data, :file_name, :ruby_dir

def initialize(file_name, mode=:new)
def initialize(file, mode=:new)
@rubyw_exe = 'rubyw.exe'
@ruby_exe = 'ruby.exe'
@file_name = file_name
@file = Pathname.new(file)
case mode
when :open
@file_data = File.read(@file_name).split("\n")
@fmode = 'r+'
@file_data = File.read(@file).split("\n")
when :new
@file_data = [header]
@fmode = 'w+'
end
yield self if block_given?
end

def bin_dir
WindowsFile.join(File.dirname(@ruby_exe))
def path
@file
end

def header
Expand Down Expand Up @@ -57,22 +55,16 @@ def echo(string)
self
end

def echo_ruby_version(verb='Switching to')
@file_data << "for /f \"delims=\" %%a in ('ruby -v') do @echo == #{verb} %%a == "
self
end

def echo_running_with_ruby_version
echo_ruby_version('Running with')
self
def remove_line(re)
@file_data.reject!{ |i| i =~ re }
end

def to_s
@file_data.join("\n")
end

def write
File.open(@file_name, @fmode){|f| f.puts self.to_s }
File.open(@file, 'w+'){|f| f.puts self.to_s }
end

end
78 changes: 7 additions & 71 deletions lib/pik/checkup.rb
@@ -1,75 +1,11 @@
class Pik
# class Pik

class Checkup
# class Checkup

def initialize(text)
@text = text
# pp @text
@output = ["Checkup results:"]
end
# def initialize(text)
# @text = text
# @output = ["Checkup results:"]
# end

def check
home
rubyopt
path
pathext

puts
puts

self
end

def to_s
ERB.new(@output.join("\n\n")).result
end

def rubyopt
unless WindowsEnv.user['rubyopt'].empty? && WindowsEnv.system['rubyopt'].empty?
fail('rubyopt')
else
pass('rubyopt')
end
end

def home
if WindowsEnv.user['home'].empty?
fail('home')
else
pass('home')
end
end

def path
dirs = (WindowsEnv.user['path'] + WindowsEnv.system['path']).split(';')
dirs = dirs.select{|dir| File.exist?( File.join(dir,'ruby.exe') ) }
unless dirs.size == 1
fail('path')
else
pass('path')
end
end

def pathext
p_ext = WindowsEnv.system['pathext'].downcase
unless p_ext.include?('.rb') && p_ext.include?('.rbw')
fail('pathext')
else
pass('pathext')
end
end

def pass(test)
print '.'
$stdout.flush
@output << @text[test][:pass]
end

def fail(test)
print 'F'
@output << @text[test][:fail]
end

end

end
# end
35 changes: 35 additions & 0 deletions lib/pik/commands.rb
@@ -0,0 +1,35 @@
module Pik

module Commands

def self.clear
commands.clear
end

def self.add(command)
commands << command
end

def self.find(command)
commands.find{ |cmd| cmd.names.include?(command.to_sym) }
end

def self.list
commands.map{|c| c.names }.flatten
end

def self.description
commands.sort_by{|c| c.name }.map do |cmd|
" %-15s %s" % [cmd.names.join('|'), cmd.summary]
end.join("\n") +
"\n\nFor help on a particular command, use 'pik help COMMAND'."
end

def self.commands
@commands ||= []
end


end

end

0 comments on commit 341fbd1

Please sign in to comment.