-
I'm writing a CLI program that has a complex bunch of arguments, many of which are required. But kind of like how "--help" bypasses the necessity for the rest of the command line to exist, I'd also like a "--version" option that would behave similarly and just cause the program to output its version number and exit successfully. How can I accomplish this in any easy manner? I suppose that I could always include the version in the program summary that is output by "--help", but ideally I'd like to have a separate option for the version number. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
So, two answers:
let programOpts = ??? // your normal program options go here
let versionOpts = Opts.flag("version", "Print version information and exit").map(_ => println("Version 1.0"))
let opts = programOpts orElse versionOpts
Many people start by just using |
Beta Was this translation helpful? Give feedback.
So, two answers:
CommandApp
, you can pass aversion
string to the constructor, like so:decline/core/jvm/src/test/scala/com/monovore/example/decline/ListDir.scala
Lines 7 to 10 in f6752ea
--version
option quite easily also:CommandApp
's version flag is actually implemented like this under the hood.Many people st…