</div><!-- fragment --><h1><aclass="anchor"id="autotoc_md1"></a>
Note</h1>
<p>These examples reference exceptions. These are not enabled by default. The default behaviour for user-fault exceptions is to produce output to <code>stderr</code> and kill the process. <br/>
<p>Super easily! Just grab the latest files (2) from <ahref="https://github.com/Leonetienne/Hazelnupp/tree/master/INCLUDE">/INCLUDE</a> and put them into your project! You may have to add the .cpp to your compile list, but most IDEs should do this automatically.</p>
<p>So what's the simplest way to use Hazelnupp to work with command-line parameters? See: </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "Hazelnupp.h"</span></div>
</div><!-- fragment --><p>Looks super easy! But what about actual values? </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "Hazelnupp.h"</span></div>
</div><!-- fragment --><p>What about lists? </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "Hazelnupp.h"</span></div>
<p>Abbreviations are a very important part of command line arguments. Like, typing <code>-f</code> instead of <code>--force</code>. Here's how to use them in Hazelnupp: </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "Hazelnupp.h"</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (args.<aclass="code"href="classHazelnp_1_1CmdArgsInterface.html#a3a7fa36fe69ee8bf3b400983a21ecd24">HasParam</a>(<spanclass="stringliteral">"--force"</span>)) <spanclass="comment">// This key will be present, even if the user passed '-f'</span></div>
<divclass="line"> args.<aclass="code"href="classHazelnp_1_1CmdArgsInterface.html#aa30222df012f357455f90e3620346bb2">RegisterConstraint</a>(<spanclass="stringliteral">"--this-is-required"</span>, <aclass="code"href="structHazelnp_1_1ParamConstraint.html#a926e12fcb2fd0d031452c4bcc950bd6c">ParamConstraint::Require</a>()); <spanclass="comment">// This missing throws an exception</span></div>
<divclass="line"> args.<aclass="code"href="classHazelnp_1_1CmdArgsInterface.html#aa30222df012f357455f90e3620346bb2">RegisterConstraint</a>(<spanclass="stringliteral">"--also-required-but-defaulted"</span>, <aclass="code"href="structHazelnp_1_1ParamConstraint.html#a926e12fcb2fd0d031452c4bcc950bd6c">ParamConstraint::Require</a>({<spanclass="stringliteral">"122"</span>})); <spanclass="comment">// This will default to 122</span></div>
<p>The conversions <code>*->list</code> just create a list with a single entry (except for <code>void->list</code> which produces an empty list). <br/>
</div><!-- fragment --><p>If <code>--this-must-be-int</code> 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.</p>
<p> Note that you can also combine these two constraint-types by populating the struct yourself: </p><divclass="fragment"><divclass="line">ParamConstraint pc;</div>
</div><!-- fragment --><p>What doesn't work is inserting multiple constraints for one key. It will just discard the older one. But that's okay because one can describe all possible constraints for a single key in <b>one</b> struct.</p>
</div><!-- fragment --><p>What does this automatically generated documentation look like? </p><divclass="fragment"><divclass="line">$ a.out --help</div>
<divclass="line"></div>
<divclass="line">This is the testing application for Hazelnupp.</div>
<divclass="line"></div>
<divclass="line">==== AVAILABLE PARAMETERS ====</div>
<divclass="line"></div>
<divclass="line">--help This will display the parameter documentation.</div>
</div><!-- fragment --><p>Additionally you can provide a brief description of your application to be added right above the parameter list. </p><divclass="fragment"><divclass="line">CmdArgsInterface args;</div>
</div><!-- fragment --><p>If you want to display this information somewhere else, you can always access it as a string via <code>args.GenerateDocumentation()</code>.</p>
<p>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.</p>
<divclass="line">--width => The width of something...</div>
</div><!-- fragment --><p>This assumes that you've set a description for, in this example, <code>--width</code>. If a description is not set, the last line will simply be omitted.</p>
<p>Chaining abbreviated parameters, like this: </p><divclass="fragment"><divclass="line"># This is not supported. It would think -ltr is one parameter.</div>
Just create an issue with the tag <code>feature request</code>. Don't forget to update the UML (<code>Hazelnupp.vpp</code>)! The (free) modelling software used is <ahref="https://www.visual-paradigm.com">Visual Paradigm</a>. <br/>
<li>Enumerations (and their values) and macros are all-upper case snake-case</li>
<li>No <code>using namespace std</code></li>
<li>Do <code>using namespace <aclass="el"href="namespaceHazelnp.html">Hazelnp</a></code> in cpp files. Don't do <code><aclass="el"href="namespaceHazelnp.html">Hazelnp</a>::</code> if possible</li>
<li>Files outside the project (like STL) have to be included with <code>#include <></code>. Not <code>""</code></li>
<divclass="fragment"><divclass="line">Copyright (c) 2021, Leon Etienne</div>
<divclass="line"></div>
<divclass="line">Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</div>
<divclass="line"></div>
<divclass="line">Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</div>
<divclass="line">Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</div>
<divclass="line"></div>
<divclass="line">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div>
</div><!-- fragment --></div></div><!-- PageDoc -->
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html">Hazelnp::CmdArgsInterface</a></div><divclass="ttdoc">The main class to interface with.</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8h_source.html#l00011">CmdArgsInterface.h:11</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html_abf553ed4acabf9e1db357715bc10533c"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html#abf553ed4acabf9e1db357715bc10533c">Hazelnp::CmdArgsInterface::SetCatchHelp</a></div><divclass="ttdeci">void SetCatchHelp(bool catchHelp)</div><divclass="ttdoc">Sets whether the CmdArgsInterface should automatically catch the –help parameter, print the parameter...</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8cpp_source.html#l00334">CmdArgsInterface.cpp:334</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1HazelnuppInvalidKeyException_html"><divclass="ttname"><ahref="classHazelnp_1_1HazelnuppInvalidKeyException.html">Hazelnp::HazelnuppInvalidKeyException</a></div><divclass="ttdoc">Gets thrown when an non-existent key gets dereferenced.</div><divclass="ttdef"><b>Definition:</b><ahref="HazelnuppException_8h_source.html#l00029">HazelnuppException.h:29</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html_aa30222df012f357455f90e3620346bb2"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html#aa30222df012f357455f90e3620346bb2">Hazelnp::CmdArgsInterface::RegisterConstraint</a></div><divclass="ttdeci">void RegisterConstraint(const std::string &key, const ParamConstraint &constraint)</div><divclass="ttdoc">Will register a constraint for a parameter.</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8cpp_source.html#l00598">CmdArgsInterface.cpp:598</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html_aaccf591a74408aeb4363033fe8cb2224"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html#aaccf591a74408aeb4363033fe8cb2224">Hazelnp::CmdArgsInterface::RegisterAbbreviation</a></div><divclass="ttdeci">void RegisterAbbreviation(const std::string &abbrev, const std::string &target)</div><divclass="ttdoc">Will register an abbreviation (like -f for –force)</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8cpp_source.html#l00567">CmdArgsInterface.cpp:567</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html_a3a7fa36fe69ee8bf3b400983a21ecd24"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html#a3a7fa36fe69ee8bf3b400983a21ecd24">Hazelnp::CmdArgsInterface::HasParam</a></div><divclass="ttdeci">bool HasParam(const std::string &key) const</div><divclass="ttdoc">Will check wether a parameter exists given a key, or not.</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8cpp_source.html#l00165">CmdArgsInterface.cpp:165</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1CmdArgsInterface_html_a1f4845041e08b3335510de44fafaee19"><divclass="ttname"><ahref="classHazelnp_1_1CmdArgsInterface.html#a1f4845041e08b3335510de44fafaee19">Hazelnp::CmdArgsInterface::Parse</a></div><divclass="ttdeci">void Parse(const int argc, const char *const *argv)</div><divclass="ttdoc">Will parse command line arguments.</div><divclass="ttdef"><b>Definition:</b><ahref="CmdArgsInterface_8cpp_source.html#l00036">CmdArgsInterface.cpp:36</a></div></div>