![]() |
Leonetienne/Hazelnupp
Simple, easy to use, command line parameter interface
|
is a simple, easy to use command line parameter parser. Hazelnupp does not support windows-, or bsd-style arguments. Only linux-style.
What is the linux-style? This:
These examples reference exceptions. These are not enabled by default. The default behaviour for user-fault exceptions is to produce output to stderr
and kill the process. To enable exceptions, call this method:
How do i actually import this into my existing project?
Super easily! Just grab the latest files (2) from /INCLUDE and put them into your project! You may have to add the .cpp to your compile list, but most IDEs should do this automatically.
The concept is that each parameter must be one of five types. These are:
Here are examples on how to create them
These parameters can then be accessed via a simple lookup!
So what's the simplest way to use Hazelnupp to work with command-line parameters? See:
Looks super easy! But what about actual values?
What about lists?
Abbreviations are a very important part of command line arguments. Like, typing -f
instead of --force
. Here's how to use them in Hazelnupp:
That's all cool and stuff, but this looks like a LOT of error-checking and not elegant at all! How would i actually use this?
For exactly this reason, there are constraints. With this, you can control what your data looks like! Constraints serve three main purposes:
With ParamConstraint::Require()
you can declare that a paramater must either always be present, or provide a default value.
Minimal working example:
With type safety you can always be certain that you are working with the correct type! By creating a type-constraint, you force Hazelnupp to use a certain type. If a supplied type does not match, but is convertible, it will be converted. If it is not convertible, the process will terminate with a descriptive error message.
These conversions are:
The conversions *->list
just create a list with a single entry (except for void->list
which produces an empty list). The *->void
conversions just drop their value. void->string
just produces an empty string.
Minimal working example:
If --this-must-be-int
would be passed as a float, it would be converted to int. If it was passed, for example, as a string, it would throw an exception.
With parameter incompatibilities you can declare that certain parameters are just incompatible. If they get passed together, the process will terminate with a descriptive error message.
Minimal working example:
Keep in mind that you can only register ONE constraint for each parameter! Adding another one will just overwrite the prior one. However, one constraint can do all three "types" at once if you daisychain them:
Hazelnupp does automatically create a parameter documentation, accessible via --help
. If you want to use --help
yourself, just turn it off.
What does this automatically generated documentation look like?
This documentation is automatically fed by any information provided on parameters. You have to set the brief descriptions yourself though.
Additionally you can provide a brief description of your application to be added right above the parameter list.
If you want to display this information somewhere else, you can always access it as a string via args.GenerateDocumentation()
.
Given that you did not disable crash-on-error, Hazelnupps default behaviour on user error is to terminate the process with a descriptive error message to stderr.
Here's how they look like:
Type mismatch:
Missing required parameter:
This assumes that you've set a description for, in this example, --width
. If a description is not set, the last line will simply be omitted.
Check out the tests! They may help you out! Also make sure to check out the doxygen docs!
Chaining abbreviated parameters, like this:
Using parameters multiple times
This is still in alpha! There is no guarantee at all that this actually works. Whilst i did my best to make sure it does, i bet there are still a few flaws i've overlooked. Please know that i am not obliged to work on fixes. I do have other stuff to do. This does not mean that i won't, but i'm not sure when. Feel free to submit a PR if you think you improved it in any way :)
If you want to contribute, feel free to fork the repository, and submit a pull request. Bugfixes and tests are almost certain to be accepted, features should be agreed upon and come with tests. Just create an issue with the tag feature request
. Don't forget to update the UML (Hazelnupp.vpp
)! The (free) modelling software used is Visual Paradigm.
Any code added must match the existing style!
/** */
for doxygen. See existing classifiers//!
for doxygen. See existing definitions{
always gets a new lineusing namespace std
using namespace Hazelnp
in cpp files. Don't do Hazelnp::
if possible#include <>
. Not ""