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
|
# File 'lib/tinyci/cli.rb', line 16
def self.parse!(argv = ARGV)
opts = {}
global = OptionParser.new do |o|
o.banner = ''
o.on("-q", "--[no-]quiet", "surpress output") {|q| opts[:quiet] = q}
o.on("-D <DIR>", "--dir <DIR>", "specify repository location") {|d| opts[:dir] = d}
end
subcommands = {
'run' => OptionParser.new do |o|
o.banner = "#{LOGO % TinyCI::VERSION}\nGlobal options:\n #{global.help.slice(3..-1)}\nrun options:"
o.on("-c <SHA>", "--commit <SHA>", "run against a specific commit") {|c| opts[:commit] = c}
o.on("-a", "--all", "run against all commits which have not been run against before") {|a| opts[:all] = a}
end,
'install' => OptionParser.new do |o|
o.banner = "Usage: install [options]"
o.on("-q", "--[no-]quiet", "quietly run") {|v| opts[:quiet] = v}
end,
'compact' => OptionParser.new do |o|
o.banner = "Usage: compact [options]"
o.on("-n", "--num-builds-to-leave <NUM>", "number of builds to leave in place, starting from the most recent") {|n| opts[:num_builds_to_leave] = n}
o.on("-b", "--builds-to-leave <BUILDS>", "specific build directories to leave in place, comma-separated") {|b| opts[:builds_to_leave] = b.split(',')}
o.on("-q", "--[no-]quiet", "quietly run") {|v| opts[:quiet] = v}
end
}
banner = "\#{LOGO % TinyCI::VERSION}\nGlobal options:\n\#{global.help.strip}\n\nAvailable commands:\nrun build and test the repo\ninstall install the git hook into the current repository\ncompact compress old build artifacts\nversion print the TinyCI version number\n"
if argv[0] == '--help'
puts banner
return false
end
global.order!(argv)
command = argv.shift
if command.nil? || subcommands[command].nil?
puts banner
return false
end
subcommands[command].order!(argv)
opts[:dir] ||= begin
repo_root
rescue TinyCI::Subprocesses::SubprocessError => e
if e.message == '`git rev-parse --is-inside-git-dir` failed with code 32768'
exit 1
else
raise e
end
end
send "do_#{command}", opts
end
|