mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-09 04:09:31 -04:00
Updated manual for ignore unmatched args.
This commit is contained in:
parent
14ac7a1c17
commit
634cbb01f5
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Templatized C++ Command Line Parser Manual</title><link rel="stylesheet" href="style.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.71.1" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id400620"></a>Templatized C++ Command Line Parser Manual</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Michael</span> <span class="othername">E</span> <span class="surname">Smoot</span></h3></div></div><div><p class="copyright">Copyright © 2003,2004,2005,2006,2009,2011 Michael E. Smoot</p></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#BASIC_USAGE">1. Basic Usage</a></span></dt><dd><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></dd><dt><span class="chapter"><a href="#FUNDAMENTAL_CLASSES">2. Fundamental Classes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMMAND_LINE"><code class="classname">CmdLine</code></a></span></dt><dt><span class="sect1"><a href="#SWITCH_ARG"><code class="classname">SwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#VALUE_ARG"><code class="classname">ValueArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_ARG"><code class="classname">MultiArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_SWITCH_ARG"><code class="classname">MultiSwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_VALUE_ARG"><code class="classname">UnlabeledValueArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_MULTI_ARG"><code class="classname">UnlabeledMultiArg</code></a></span></dt></dl></dd><dt><span class="chapter"><a href="#COMPLICATIONS">3. Complications</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular
|
||||
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></dd><dt><span class="chapter"><a href="#NOTES">4. Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="BASIC_USAGE"></a>Chapter 1. Basic Usage</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="OVERVIEW"></a>Overview</h2></div></div></div><p>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Templatized C++ Command Line Parser Manual</title><link rel="stylesheet" href="style.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.71.1" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id417480"></a>Templatized C++ Command Line Parser Manual</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Michael</span> <span class="othername">E</span> <span class="surname">Smoot</span></h3></div></div><div><p class="copyright">Copyright © 2003,2004,2005,2006,2009,2011,2012 Michael E. Smoot</p></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#BASIC_USAGE">1. Basic Usage</a></span></dt><dd><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></dd><dt><span class="chapter"><a href="#FUNDAMENTAL_CLASSES">2. Fundamental Classes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMMAND_LINE"><code class="classname">CmdLine</code></a></span></dt><dt><span class="sect1"><a href="#SWITCH_ARG"><code class="classname">SwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#VALUE_ARG"><code class="classname">ValueArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_ARG"><code class="classname">MultiArg</code></a></span></dt><dt><span class="sect1"><a href="#MULTI_SWITCH_ARG"><code class="classname">MultiSwitchArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_VALUE_ARG"><code class="classname">UnlabeledValueArg</code></a></span></dt><dt><span class="sect1"><a href="#UNLABELED_MULTI_ARG"><code class="classname">UnlabeledMultiArg</code></a></span></dt></dl></dd><dt><span class="chapter"><a href="#COMPLICATIONS">3. Complications</a></span></dt><dd><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular
|
||||
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_UNMATCHED">I want to ignore unmatched arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></dd><dt><span class="chapter"><a href="#NOTES">4. Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></span></dt><dt><span class="sect1"><a href="#VISITORS">Visitors</a></span></dt><dt><span class="sect1"><a href="#MORE_INFO">More Information</a></span></dt></dl></dd></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="BASIC_USAGE"></a>Chapter 1. Basic Usage</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#OVERVIEW">Overview</a></span></dt><dt><span class="sect1"><a href="#EXAMPLE">Example</a></span></dt><dd><dl><dt><span class="sect2"><a href="#LIBRARY_PROPERTIES">Library Properties</a></span></dt><dt><span class="sect2"><a href="#ARG_PROPERTIES">Common Argument Properties</a></span></dt></dl></dd><dt><span class="sect1"><a href="#COMPILING">Compiling</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="OVERVIEW"></a>Overview</h2></div></div></div><p>
|
||||
<span class="emphasis"><em>TCLAP</em></span> has a few key classes to be aware of.
|
||||
The first is the
|
||||
<code class="classname">CmdLine</code> (command line) class. This class parses
|
||||
@ -414,7 +414,7 @@ then just declare the <code class="classname">UnlabeledMultiArg</code> as type
|
||||
<code class="classname">string</code> and parse the different values yourself or use
|
||||
several <code class="classname">UnlabeledValueArg</code>s.
|
||||
</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="COMPLICATIONS"></a>Chapter 3. Complications</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#COMBINE_SWITCHES">I want to combine multiple switches into one argument...</a></span></dt><dt><span class="sect1"><a href="#XOR">I want one argument or the other, but not both...</a></span></dt><dt><span class="sect1"><a href="#NO_FLAG">I have more arguments than single flags make sense for...</a></span></dt><dt><span class="sect1"><a href="#CONSTRAINT">I want to constrain the values allowed for a particular
|
||||
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></div><p>
|
||||
argument...</a></span></dt><dt><span class="sect1"><a href="#ARG_ADD_CMDLINE">I want the Args to add themselves to the CmdLine...</a></span></dt><dt><span class="sect1"><a href="#CHANGE_OUTPUT">I want different output than what is provided...</a></span></dt><dt><span class="sect1"><a href="#NO_HELP_VERSION">I don't want the --help and --version switches to be created automatically...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_ARGS">I want to ignore certain arguments...</a></span></dt><dt><span class="sect1"><a href="#IGNORE_UNMATCHED">I want to ignore unmatched arguments...</a></span></dt><dt><span class="sect1"><a href="#READING_HEX_INTEGERS">I want to read hex integers as arguments...</a></span></dt><dt><span class="sect1"><a href="#USING_ARGTRAITS">I want to use different types...</a></span></dt><dt><span class="sect1"><a href="#CHANGING_STARTSTRINGS">I want to use Windows-style flags like "/x" and "/y"...</a></span></dt></dl></div><p>
|
||||
Naturally, what we have seen to this point doesn't satisfy all of
|
||||
our needs.
|
||||
</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="COMBINE_SWITCHES"></a>I want to combine multiple switches into one argument...</h2></div></div></div><p>
|
||||
@ -703,6 +703,47 @@ ignore arguments after the <em class="parameter"><code>--</code></em>. To accomm
|
||||
we can make both <code class="classname">UnlabeledValueArg</code>s and
|
||||
<code class="classname">UnlabeledMultiArg</code>s ignoreable in their constructors.
|
||||
See the <a href="html/index.html" target="_top"> API Documentation</a> for details.
|
||||
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="IGNORE_UNMATCHED"></a>I want to ignore unmatched arguments...</h2></div></div></div><p>
|
||||
By default, if <span class="emphasis"><em>TCLAP</em></span> sees an argument that doesn't
|
||||
match a specified <code class="classname">Arg</code>, it will produce an exception.
|
||||
This strict handling provides some assurance that all input to a program
|
||||
is controlled. However, there are times when
|
||||
this strict handling of arguments might not be desirable. The alternative
|
||||
that <span class="emphasis"><em>TCLAP</em></span> provides is to simply ignore any unmatched
|
||||
arguments on the command line. This is accomplished by calling the
|
||||
<code class="methodname">ignoreUnmatched</code> method with
|
||||
<em class="parameter"><code>true</code></em> on the
|
||||
<code class="classname">CmdLine</code> object that's been constructed.
|
||||
|
||||
</p><pre class="programlisting">
|
||||
|
||||
// Define the command line object.
|
||||
CmdLine cmd("Command description message", ' ', "0.9");
|
||||
|
||||
// Tell the command line to ignore any unmatched args.
|
||||
cmd.ignoreUnmatched(true);
|
||||
|
||||
// Define a value argument and add it to the command line.
|
||||
ValueArg<string> nameArg("n","name","Name to print",true,"homer","string");
|
||||
cmd.add( nameArg );
|
||||
|
||||
// Parse the args.
|
||||
cmd.parse( argc, argv );
|
||||
|
||||
</pre><p>
|
||||
|
||||
Given the program above, if a user were to type:
|
||||
|
||||
</p><pre class="programlisting">
|
||||
|
||||
% command -n Mike something to ignore
|
||||
|
||||
</pre><p>
|
||||
|
||||
The program would succeed and the name <code class="classname">ValueArg</code>
|
||||
would be populated with "Mike" but
|
||||
the strings "something", "to", and "ignore" would simply be ignored by the
|
||||
parser.
|
||||
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="READING_HEX_INTEGERS"></a>I want to read hex integers as arguments...</h2></div></div></div><p>
|
||||
Sometimes it's desirable to read integers formatted in decimal, hexadecimal,
|
||||
and octal format. This is now possible by #defining the <em class="parameter"><code>TCLAP_SETBASE_ZERO</code></em>
|
||||
|
@ -30,7 +30,7 @@
|
||||
<othername role='mi'>E</othername>
|
||||
</author>
|
||||
<copyright>
|
||||
<year>2003,2004,2005,2006,2009,2011</year>
|
||||
<year>2003,2004,2005,2006,2009,2011,2012</year>
|
||||
<holder>Michael E. Smoot</holder>
|
||||
</copyright>
|
||||
</bookinfo>
|
||||
@ -903,6 +903,52 @@ See the <ulink url="html/index.html"> API Documentation</ulink> for details.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="IGNORE_UNMATCHED">
|
||||
<title>I want to ignore unmatched arguments...</title>
|
||||
<para>
|
||||
By default, if <emphasis>TCLAP</emphasis> sees an argument that doesn't
|
||||
match a specified <classname>Arg</classname>, it will produce an exception.
|
||||
This strict handling provides some assurance that all input to a program
|
||||
is controlled. However, there are times when
|
||||
this strict handling of arguments might not be desirable. The alternative
|
||||
that <emphasis>TCLAP</emphasis> provides is to simply ignore any unmatched
|
||||
arguments on the command line. This is accomplished by calling the
|
||||
<methodname>ignoreUnmatched</methodname> method with
|
||||
<parameter>true</parameter> on the
|
||||
<classname>CmdLine</classname> object that's been constructed.
|
||||
|
||||
<programlisting>
|
||||
|
||||
// Define the command line object.
|
||||
CmdLine cmd("Command description message", ' ', "0.9");
|
||||
|
||||
// Tell the command line to ignore any unmatched args.
|
||||
cmd.ignoreUnmatched(true);
|
||||
|
||||
// Define a value argument and add it to the command line.
|
||||
ValueArg<string> nameArg("n","name","Name to print",true,"homer","string");
|
||||
cmd.add( nameArg );
|
||||
|
||||
// Parse the args.
|
||||
cmd.parse( argc, argv );
|
||||
|
||||
</programlisting>
|
||||
|
||||
Given the program above, if a user were to type:
|
||||
|
||||
<programlisting>
|
||||
|
||||
% command -n Mike something to ignore
|
||||
|
||||
</programlisting>
|
||||
|
||||
The program would succeed and the name <classname>ValueArg</classname>
|
||||
would be populated with "Mike" but
|
||||
the strings "something", "to", and "ignore" would simply be ignored by the
|
||||
parser.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="READING_HEX_INTEGERS">
|
||||
<title>I want to read hex integers as arguments...</title>
|
||||
<para>
|
||||
|
Loading…
x
Reference in New Issue
Block a user