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
|
# File 'lib/dependagrab/cli.rb', line 6
def self.start
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--version', '-v', GetoptLong::NO_ARGUMENT ],
[ '--output', '-o', GetoptLong::REQUIRED_ARGUMENT ],
)
options = {}
begin
opts.each do |opt, arg|
case opt
when '--help'
print_help
exit 0
when '--version'
puts "dependagrab #{Dependagrab::VERSION}"
exit 0
when '--output'
options[:output] = arg
end
end
rescue GetoptLong::Error => e
STDERR.puts "Error: #{e.message} (set DEBUG=true for detailed backtrace)"
puts
print_help
STDERR.puts e.backtrace if ENV['DEBUG']
exit 1
end
if ARGV.length != 1
STDERR.puts "Missing REPO argument (try --help for usage)"
exit 1
end
repo = ARGV.shift
_, options[:owner], options[:repo] = repo.split /([\w_-]+)\/([\w._-]+)$/
if options[:owner].nil? || options[:repo].nil?
STDERR.puts "Invalid REPO format"
exit 1
end
begin
options.merge!(print: true)
Dependagrab.run(options)
rescue => e
STDERR.puts "Error: #{e.message} (set DEBUG=true for detailed backtrace)"
STDERR.puts e.backtrace if ENV['DEBUG']
exit 1
end
end
|