Commit d7506754 authored by Eloy Duran's avatar Eloy Duran

More work on help system.

parent 422cc7eb
......@@ -5,7 +5,7 @@ module Pod
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 @@ module Pod
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 @@ module Pod
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 @@ module Pod
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 @@ module Pod
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,25 +26,21 @@ module Pod
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
......@@ -52,14 +48,16 @@ module Pod
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment