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
|
# File 'lib/deadlist/cli/argument_parser.rb', line 2
def self.parse(args, version)
params = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: deadlist [options]"
opts.separator ""
opts.separator "Required options:"
opts.on("-i", "--id ID", "ID of show(s) to download (comma-separated for multiple)") do |id|
params[:ids] = id.split(',').map(&:strip)
end
opts.on("-f", "--format FORMAT", "Format to download (mp3, flac, ogg)") do |format|
params[:format] = format.downcase
end
opts.separator ""
opts.separator "Other options:"
opts.on("-d", "--directory PATH", "Directory to save show(s) to. Will default to /shows/ in the execution directory") do |dir|
params[:directory] = dir
end
opts.on("-h", "--help", "Show this help") do
puts opts
exit
end
opts.on("-v", "--version", "Show version") do
puts "deadlist v#{version}"
exit
end
opts.on('-q', '--quiet', 'Run silently') do
params[:quiet] = true
end
opts.on('--dry-run', 'List tracks to be downloaded') do
params[:dry_run] = true
end
end
parser.parse!(args)
validate_required_params!(params, parser)
params
rescue OptionParser::InvalidOption => e
puts "Error: #{e.message}"
puts parser
exit(1)
end
|