Permalink
Browse files

More work on help system.

  • Loading branch information...
alloy committed Sep 13, 2011
1 parent 422cc7e commit d7506754065a78c11f4e9eb522f2db20b49899ef
Showing with 39 additions and 29 deletions.
  1. +17 −8 lib/cocoa_pods/command.rb
  2. +4 −4 lib/cocoa_pods/command/install.rb
  3. +10 −12 lib/cocoa_pods/command/repo.rb
  4. +8 −5 lib/cocoa_pods/command/setup.rb
View
@@ -5,7 +5,7 @@ class Command
autoload :Setup, 'cocoa_pods/command/setup'
autoload :Spec, 'cocoa_pods/command/spec'
- class Help
+ class Help < Exception
def initialize(command_class, argv)
@command_class, @argv = command_class, argv
end
@@ -20,6 +20,13 @@ def run
end
end
+ class ARGV < Array
+ def options; select { |x| x[0,1] == '-' }; end
+ def arguments; self - options; end
+ def option(name); !!delete(name); end
+ def shift_argument; (arg = arguments[0]) && delete(arg); end
+ end
+
def self.banner
"### Commands\n" +
"\n" +
@@ -35,11 +42,11 @@ def self.options
end
def self.parse(*argv)
- argv = argv.dup
- show_help = argv.delete('--help')
- Config.instance.verbose = !!argv.delete('--verbose')
+ argv = ARGV.new(argv)
+ show_help = argv.option('--help')
+ Config.instance.verbose = argv.option('--verbose')
- command_class = case argv.shift
+ command_class = case argv.shift_argument
when 'install' then Install
when 'repo' then Repo
when 'setup' then Setup
@@ -49,14 +56,16 @@ def self.parse(*argv)
if show_help || command_class.nil?
Help.new(command_class || self, argv)
else
- command_class.new(*argv)
+ command_class.new(argv)
end
+ rescue Help => help
+ return help
end
include Config::Mixin
- def initialize(*argv)
- raise ArgumentError, "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
+ def initialize(argv)
+ raise Help.new(self.class, argv)
end
end
end
@@ -18,12 +18,12 @@ def self.options
super
end
- def initialize(*argv)
- config.clean = !argv.delete('--no-clean')
- if podspec = argv.shift
+ def initialize(argv)
+ config.clean = !argv.option('--no-clean')
+ if podspec = argv.shift_argument
@podspec = Pathname.new(podspec)
end
- super
+ super unless argv.empty?
end
def run
@@ -26,40 +26,38 @@ def self.banner
include Executioner
executable :git
- def initialize(*argv)
- case @action = argv[0]
- when'add'
+ def initialize(argv)
+ case @action = argv.arguments[0]
+ when 'add'
unless (@name = argv[1]) && (@url = argv[2])
raise ArgumentError, "needs a NAME and URL"
end
when 'update'
@name = argv[1]
- when 'cd'
- unless @name = argv[1]
- raise ArgumentError, "needs a NAME"
- end
else
super
end
end
def dir
- File.join(config.repos_dir, @name)
+ config.repos_dir + @name
end
def run
send @action
end
def add
- FileUtils.mkdir_p(config.repos_dir)
+ puts "==> Cloning spec repo `#{@name}' from `#{@url}'"
+ config.repos_dir.mkpath
Dir.chdir(config.repos_dir) { git("clone #{@url} #{@name}") }
end
def update
- names = @name ? [@name] : Dir.entries(config.repos_dir)[2..-1]
- names.each do |name|
- Dir.chdir(File.join(config.repos_dir, name)) { git("pull") }
+ dirs = @name ? [dir] : config.repos_dir.children
+ dirs.each do |dir|
+ puts "==> Updating spec repo `#{dir.basename}'"
+ Dir.chdir(dir) { git("pull") }
end
end
end
@@ -4,13 +4,16 @@ module Pod
class Command
class Setup < Command
def self.banner
-%{### Setup
+%{### Setup CocoaPods environment
- $ pod help setup
+ $ pod setup
- pod setup
- Creates a directory at `~/.cocoa-pods' which will hold your spec-repos.
- This is where it will create a clone of the public `master' spec-repo.}
+ Creates a directory at `~/.cocoa-pods' which will hold your spec-repos.
+ This is where it will create a clone of the public `master' spec-repo.}
+ end
+
+ def initialize(argv)
+ super unless argv.empty?
end
def master_repo_url

0 comments on commit d750675

Please sign in to comment.