</div><!-- fragment --><divclass="fragment"><divclass="line"># Using an abbreviated parameter</div>
<divclass="line">a.out -lp 1234</div>
</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 "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</span></div>
</div><!-- fragment --><p>Looks super easy! But what about actual values? </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</span></div>
</div><!-- fragment --><p>What about lists? </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</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 "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (args.<aclass="code"href="classHazelnp_1_1Hazelnupp.html#a8b79a79d40420ae748c108c691111040">HasParam</a>(<spanclass="stringliteral">"--force"</span>)) <spanclass="comment">// This key will be present, even if the user passed '-f'</span></div>
<li>If a parameter is not present, but has a default value, it will be automatically created.</li>
<li>If a parameter is not present, and has no default value, an exception will be thrown.</li>
</ul>
<p>Minimal working example: </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</span></div>
<divclass="line"><aclass="code"href="structHazelnp_1_1ParamConstraint.html#afbcc75c428381ab3a292d3f55945eb32">ParamConstraint::Require</a>(<spanclass="stringliteral">"--this-is-required"</span>), <spanclass="comment">// This missing throws an exception</span></div>
<divclass="line"><aclass="code"href="structHazelnp_1_1ParamConstraint.html#afbcc75c428381ab3a292d3f55945eb32">ParamConstraint::Require</a>(<spanclass="stringliteral">"--also-required-but-defaulted"</span>, {<spanclass="stringliteral">"122"</span>}), <spanclass="comment">// This will default to 122</span></div>
If a supplied type does not match, but is convertible, it will be converted. <br/>
If it is not convertible, an exception will be thrown.</p>
<p>These conversions are:</p><ul>
<li>int -> [float, string, list, void]</li>
<li>float ->[int, string, list, void]</li>
<li>string -> [list, void]</li>
<li>list -> [void]</li>
<li>void -> [list]</li>
</ul>
<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/>
The <code>*->void</code> conversions just drop their value.</p>
<p>Minimal working example: </p><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include "<aclass="code"href="Hazelnupp_8h.html">Hazelnupp.h</a>"</span></div>
</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 oldest 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>
<divclass="line"></div>
<divclass="line">--name LIST default=['peter''hannes'] The names to target</div>
<divclass="line"></div>
<divclass="line">--force -f Just forces it.</div>
<divclass="line"></div>
<divclass="line">--width -w FLOAT The width of something...</div>
<divclass="line"></div>
<divclass="line">--fruit STRING [[REQUIRED]] The fruit to use</div>
<divclass="line"></div>
<divclass="line">--height -h</div>
</div><!-- fragment --><p>This documentation is automatically fed by any information provided on parameters. <br/>
You have to set the brief descriptions yourself though. </p><divclass="fragment"><divclass="line">Hazelnupp args;</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">Hazelnupp args;</div>
<divclass="line">args.SetBriefDescription(<spanclass="stringliteral">"This is the testing application for Hazelnupp."</span>);</div>
</div><!-- fragment --><p>If you want to display this information somewhere else, you can always access it via <code>args.GenerateDocumentation()</code>.</p>
<p>Chaining abbreviated parameters, like this: </p><divclass="fragment"><divclass="line"># This is not supported. It would think -ltr is one parameter.</div>
<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_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#l00026">HazelnuppException.h:26</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1Hazelnupp_html"><divclass="ttname"><ahref="classHazelnp_1_1Hazelnupp.html">Hazelnp::Hazelnupp</a></div><divclass="ttdoc">The main class to interface with.</div><divclass="ttdef"><b>Definition:</b><ahref="Hazelnupp_8h_source.html#l00011">Hazelnupp.h:11</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1Hazelnupp_html_a60e0a51cd92014a87e44322158e45872"><divclass="ttname"><ahref="classHazelnp_1_1Hazelnupp.html#a60e0a51cd92014a87e44322158e45872">Hazelnp::Hazelnupp::SetCatchHelp</a></div><divclass="ttdeci">void SetCatchHelp(bool catchHelp)</div><divclass="ttdoc">Sets whether the Hazelnupp should automatically catch the –help parameter, print the parameter docume...</div><divclass="ttdef"><b>Definition:</b><ahref="Hazelnupp_8cpp_source.html#l00295">Hazelnupp.cpp:295</a></div></div>
<divclass="ttc"id="aclassHazelnp_1_1Hazelnupp_html_a8b79a79d40420ae748c108c691111040"><divclass="ttname"><ahref="classHazelnp_1_1Hazelnupp.html#a8b79a79d40420ae748c108c691111040">Hazelnp::Hazelnupp::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="Hazelnupp_8cpp_source.html#l00164">Hazelnupp.cpp:164</a></div></div>