我正在使用 Ruby 的optparse
库来解析我的命令行应用程序的选项,但我不知道如何也接受命令。
它会是这样的:
commit -f -d init
init
在这种情况下将是命令。它并不总是必需的,因为如果用户没有提供任何命令,则应该运行一个默认命令。
这是我现在拥有的代码:
OptionParser.new do |opts|
opts.banner = %Q!Usage:
pivotal_commit # to commit with a currently started issue
pivotal_commit -f # to commit with a currently started issue and finish it
pivotal_commit -d # to commit with a currently started issue and deliver it
pivotal_commit init -e "me@gmail.com" -p my_password -l #to generate a config file at the current directory!
opts.on("-e", "--email [EMAIL]", String, "The email to the PT account you want to access") do |v|
options[:email] = v
end
opts.on("-p", "--password [PASSWORD]", String, "The password to the PT account you want to access") do |v|
options[:password] = v
end
opts.on("-f", '--finish', 'Finish the story you were currently working on after commit') do |v|
options[:finish] = v
end
opts.on('-d', '--deliver', 'Deliver the story you were currently working on after commit') do |v|
options[:deliver] = v
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
opts.on_tail('-v', '--version', 'Show version') do
puts "pivotal_committer version: #{PivotalCommitter::VERSION}"
exit
end
end.parse!