Ruby의 optparse
라이브러리를 사용하여 내 명령 행 응용 프로그램의 옵션을 구문 분석하지만 명령을 수락하는 방법을 알 수 없습니다.두 매개 변수 옵션을 명령으로 사용하도록 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 "[email protected]" -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!