How to parse parameters without an external dependency. Great question! You may be interested in picocli.
Picocli is specifically designed to solve the problem asked in the question: it is a command line parsing framework in a single file, so you can include it in source form. This lets users run picocli-based applications without requiring picocli as an external dependency.
It works by annotating fields so you write very little code. Quick summary:
- Strongly typed everything - command line options as well as positional parameters
- Support for POSIX clustered short options (so it handles
-xvfInputFile as well as -x -v -f InputFile)
- An arity model that allows a minimum, maximum and variable number of parameters, e.g,
"1..*", "3..5"
- Fluent and compact API to minimize boilerplate client code
- Subcommands
- Usage help with ANSI colors
The usage help message is easy to customize with annotations (without programming). For example:
(source)
I couldn't resist adding one more screenshot to show what kind of usage help messages are possible. Usage help is the face of your application, so be creative and have fun!
Disclaimer: I created picocli. Feedback or questions very welcome. It is written in java, but let me know if there is any issue using it in scala and I'll try to address it.