-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
command.rb
93 lines (80 loc) · 2.49 KB
/
command.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Pod
class Command
autoload :Install, 'cocoapods/command/install'
autoload :Repo, 'cocoapods/command/repo'
autoload :Search, 'cocoapods/command/search'
autoload :Setup, 'cocoapods/command/setup'
autoload :Spec, 'cocoapods/command/spec'
class Help < Informative
def initialize(command_class, argv)
@command_class, @argv = command_class, argv
end
def message
[
@command_class.banner,
'',
'Options',
'-------',
'',
@command_class.options
].join("\n")
end
end
class ARGV < Array
def options; select { |x| x.to_s[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
"To see help for the available commands run:\n" \
"\n" \
" * $ pod setup --help\n" \
" * $ pod search --help\n" \
" * $ pod install --help\n" \
" * $ pod repo --help\n" \
" * $ pod spec --help"
end
def self.options
" --help Show help information\n" \
" --silent Print nothing\n" \
" --verbose Print more information while working\n" \
" --version Prints the version of CocoaPods"
end
def self.run(*argv)
parse(*argv).run
rescue Exception => e
unless e.is_a?(Informative)
puts "Oh no, an error occurred. Please run with `--verbose' and report " \
"on https://github.com/CocoaPods/CocoaPods/issues."
puts ""
end
puts e.message
puts *e.backtrace if Config.instance.verbose
exit 1
end
def self.parse(*argv)
argv = ARGV.new(argv)
raise Informative, VERSION if argv.option('--version')
show_help = argv.option('--help')
Config.instance.silent = argv.option('--silent')
Config.instance.verbose = argv.option('--verbose')
command_class = case argv.shift_argument
when 'install' then Install
when 'repo' then Repo
when 'search' then Search
when 'setup' then Setup
when 'spec' then Spec
end
if show_help || command_class.nil?
raise Help.new(command_class || self, argv)
else
command_class.new(argv)
end
end
include Config::Mixin
def initialize(argv)
raise Help.new(self.class, argv)
end
end
end