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
|
# File 'lib/invoices/controllers/application_controller.rb', line 21
def parse_options
options = {}
subcommand_help = "\nExamples:\nCreate an invoice: invoices invoice -c 'Client Name'\nCreate a biller: invoices biller -n\nCreate a client: invoices client -n"
@global = OptionParser.new do |opt|
opt.banner = "Usage: invoices options [subcommand [options]]"
opt.on("-v", "--version", "Check the version of Invoices") do puts "v#{INVOICES_VERSION}"
end
opt.on("-h", "--help", "Get some help") do puts @global
puts subcommand_help
end
end
subcommands = {
'invoice' => OptionParser.new do |opt|
opt.on("-c", "--client CLIENT", "Select the client for this invoice") do |v|
client = Client.new.find_by_name(v)
InvoicesController.new(client)
end
end,
'biller' => OptionParser.new do |opt|
opt.on("-n", "--new", "Add a new biller to the database") do BillersController.new
end
end,
'client' => OptionParser.new do |opt|
opt.on("-n", "--new", "Add a new client to the database") do ClientsController.new
end
end
}
@global.order!
cmd = ARGV.shift
if cmd subcommands[cmd].order!
else
puts @global
puts subcommand_help
end
end
|