nidas v1.2.3
|
Extend NidasAppArg so the default input specifier and port can be customized, which in turn updates the usage string. More...
#include <NidasApp.h>
Public Member Functions | |
void | setDefaultInput (const std::string &spec, int port=0) |
Set a default input. | |
void | setRequired (bool isRequired=true) |
Set whether this argument is required. | |
bool | isRequired () |
Return whether this argument is required. | |
void | acceptShortFlag (bool enable) |
Set whether short flags are enabled or not. | |
void | addFlag (const std::string &flag) |
Add a flag which this argument should accept. | |
void | setFlags (const std::string &flags) |
Completely replace the flags which this argument should accept. | |
operator nidas_app_arglist_t () | |
Provide conversion to an arglist so a single NidasAppArg can be passed where an arglist is expected. | |
std::string | usage (const std::string &indent=" ", bool brief=false) |
Render the usage string for this particular argument, taking into account which flags are enabled. | |
bool | specified () |
Return true if this argument has been filled in from a command-line argument list, such as after a call to NidasApp::parseArgs(). | |
const std::string & | getValue () |
If this argument has been parsed from a command line list (specified() returns true), then return the value passed after the flag. | |
const std::string & | getFlag () |
Return the command-line flag which this argument consumed. | |
bool | asBool () |
An argument is true if it is a stand-alone flag and was specified in the arguments, or else if the flag value evaluates to true. | |
int | asInt () |
Parse the argument value as an integer, where the value could be the default if no value has been explicitly parsed with parse(). | |
float | asFloat () |
Same as asInt(), except parse the argument value as a float. | |
virtual bool | parse (const ArgVector &argv, int *argi=0) |
If argv[argi] matches this argument, then set the flag that was found and also the value if this argument takes a value, and return true. | |
bool | accept (const std::string &flag) |
Return true if the given command-line flag matches one of this argument's flags. | |
void | setUsageString (const std::string &text) |
std::string | getUsageFlags () |
Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting. | |
void | setDefault (const std::string &dvalue) |
std::string | getDefault () |
Public Attributes | |
bool | allowFiles |
bool | allowSockets |
Protected Member Functions | |
bool | single () |
Return true for arguments which are only a single argument. | |
Protected Attributes | |
std::string | _flags |
std::string | _syntax |
std::string | _usage |
std::string | _default |
std::string | _arg |
std::string | _value |
bool | _enableShortFlag |
bool | _required |
Private Member Functions | |
NidasAppInputFilesArg () | |
void | updateUsage () |
virtual | ~NidasAppInputFilesArg () |
Private Attributes | |
std::string | default_input |
int | default_port |
Friends | |
class | NidasApp |
Extend NidasAppArg so the default input specifier and port can be customized, which in turn updates the usage string.
|
inlineprivate |
|
inlineprivatevirtual |
Return true if the given command-line flag
matches one of this argument's flags.
References nidas::core::NidasAppArg::_default, nidas::core::NidasAppArg::_enableShortFlag, nidas::core::NidasAppArg::_flags, nidas::core::NidasAppArg::_value, and nidas::core::NidasAppArg::single().
Referenced by nidas::core::BadSampleFilterArg::parse(), and nidas::core::NidasAppArg::parse().
Set whether short flags are enabled or not.
Pass enable
as false to disable short flags and require only long flags instead. By default short flags are enabled.
References nidas::core::NidasAppArg::_enableShortFlag.
Referenced by PacketReader::parseRunstring(), and NidsMerge::parseRunstring().
Add a flag which this argument should accept.
Use this to allow an application to accept deprecated flags like -B and -E.
References nidas::core::NidasAppArg::_flags, and nidas::core::getSample().
|
inherited |
An argument is true if it is a stand-alone flag and was specified in the arguments, or else if the flag value evaluates to true.
References nidas::core::NidasAppArg::_flags, nidas::core::getSample(), and nidas::core::NidasAppArg::getValue().
Referenced by DataStats::parseRunstring(), DataPrep::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), DataStats::printReport(), NidsMerge::run(), nidas::core::NidasApp::setFileSetTimes(), nidas::core::NidasApp::setOutputClipping(), nidas::core::NidasApp::setupDaemon(), nidas::core::NidasApp::setupDaemonLogging(), and TeeI2C::writeOutput().
|
inherited |
Same as asInt(), except parse the argument value as a float.
References nidas::core::NidasAppArg::_flags, nidas::core::getSample(), and nidas::core::NidasAppArg::getValue().
Referenced by nidas::core::NidasApp::getSorterLength(), and DataDump::parseRunstring().
|
inherited |
Parse the argument value as an integer, where the value could be the default if no value has been explicitly parsed with parse().
Throw NidasAppException if the whole value cannot be parsed as an integer. See also asFloat().
References nidas::core::NidasAppArg::_flags, nidas::core::getSample(), and nidas::core::NidasAppArg::getValue().
Referenced by DataStats::parseRunstring(), DataPrep::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), and DataPrep::run().
|
inlineinherited |
References nidas::core::NidasAppArg::_default.
|
inherited |
Return the command-line flag which this argument consumed.
For example, if an argument with multiple flags is matched, then getFlag() returns the flag that matched the argument.
References nidas::core::NidasAppArg::_arg.
|
inherited |
Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting.
References nidas::core::NidasAppArg::_default, nidas::core::NidasAppArg::_enableShortFlag, nidas::core::NidasAppArg::_flags, nidas::core::getSample(), and nidas::core::NidasAppArg::single().
Referenced by nidas::core::NidasAppArg::usage().
|
inherited |
If this argument has been parsed from a command line list (specified() returns true), then return the value passed after the flag.
Otherwise return the default value.
References nidas::core::NidasAppArg::_default, nidas::core::NidasAppArg::_value, and nidas::core::NidasAppArg::specified().
Referenced by nidas::core::NidasAppArg::asBool(), nidas::core::NidasAppArg::asFloat(), nidas::core::NidasAppArg::asInt(), nidas::core::NidasApp::checkPidFile(), nidas::core::NidasApp::getSorterLength(), DataStats::jsonReport(), nidas::core::NidasApp::parseNext(), DataPrep::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and StatsProcess::run().
|
inherited |
Return whether this argument is required.
See setRequired().
References nidas::core::NidasAppArg::_required.
Referenced by nidas::core::NidasAppArg::setRequired().
|
inlineinherited |
Provide conversion to an arglist so a single NidasAppArg can be passed where an arglist is expected.
References nidas::core::getSample().
If argv[argi] matches this argument, then set the flag that was found and also the value if this argument takes a value, and return true.
Otherwise return false. The vector is not modified, but if argi is nonzero, then it is used as the starting index into argv, and it is advanced according to the number of elements of argv consumed by this argument. This method is virtual so subclasses can implement customized parsing, such as optionally consuming more than one argument following a flag.
Reimplemented in nidas::core::BadSampleFilterArg.
References nidas::core::NidasAppArg::_arg, nidas::core::NidasAppArg::_value, nidas::core::NidasAppArg::accept(), nidas::core::expectArg(), nidas::core::getSample(), and nidas::core::NidasAppArg::single().
References nidas::core::NidasAppArg::_default, and nidas::core::getSample().
Referenced by nidas::core::NidasApp::NidasApp().
|
inline |
Set a default input.
Typically spec
is a default hostname or address, and a default port can be passed in default_port
. Set just a default port by passing an empty string in spec
, in which case there is no valid default input, but a socket input string specified without a port (like sock:localhost) will use the default port.
References default_input, default_port, nidas::core::getSample(), port, and updateUsage().
Referenced by DataStats::DataStats(), DataDump::parseRunstring(), DataPrep::parseRunstring(), and StatsProcess::parseRunstring().
Completely replace the flags which this argument should accept.
This should be avoided if possible, otherwise the flags will not be consistent across applications. However, in some cases this is necessary to remove a conflicting short flag.
References nidas::core::NidasAppArg::_flags.
Referenced by DataPrep::parseRunstring(), and StatsProcess::parseRunstring().
Set whether this argument is required.
A required argument must be supplied on the command line even if it has a default value. If an argument is not required because it has a default value, then an application should not set that argument to be required.
Defaults to true, but the client may disable this option by setting the argument to false.
References nidas::core::NidasAppArg::_required, and nidas::core::NidasAppArg::isRequired().
References nidas::core::NidasAppArg::_usage, and nidas::core::getSample().
Referenced by nidas::core::NidasApp::NidasApp(), DataPrep::parseRunstring(), and updateUsage().
|
protectedinherited |
Return true for arguments which are only a single argument.
They are a single command-line flag with no following value, and typically implying a boolean value. This is equivalent to not specifying a syntax when the argument is created.
References nidas::core::NidasAppArg::_syntax.
Referenced by nidas::core::NidasAppArg::accept(), nidas::core::NidasAppArg::getUsageFlags(), and nidas::core::NidasAppArg::parse().
|
inherited |
Return true if this argument has been filled in from a command-line argument list, such as after a call to NidasApp::parseArgs().
If true, then this argument stores the flag that was recognized, and also the value of any additional parameters to this argument.
References nidas::core::NidasAppArg::_arg.
Referenced by DataStats::addCounter(), nidas::core::NidasAppArg::getValue(), TeeI2C::parseRunstring(), DataStats::report(), StatsProcess::run(), and nidas::core::NidasApp::setupDaemonLogging().
|
private |
References allowFiles, allowSockets, default_input, default_port, nidas::core::getSample(), and nidas::core::NidasAppArg::setUsageString().
Referenced by setDefaultInput().
|
inherited |
Render the usage string for this particular argument, taking into account which flags are enabled.
The returned string is formatted like below, each line prefixed with indent
, and always ends in a newline. If * brief
is true, the usage lines are omitted.
<indent><flag>[,<flag>...] [<syntax>] [default: <default>] <indent><indent>Description line one <indent><indent>Description line two ...
References nidas::core::NidasAppArg::_default, nidas::core::NidasAppArg::_syntax, nidas::core::NidasAppArg::_usage, nidas::core::getSample(), nidas::core::NidasAppArg::getUsageFlags(), and len.
Referenced by nidas::core::NidasApp::usage().
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Referenced by nidas::core::NidasAppArg::isRequired(), and nidas::core::NidasAppArg::setRequired().
|
protectedinherited |
Referenced by nidas::core::NidasAppArg::single(), and nidas::core::NidasAppArg::usage().
|
protectedinherited |
Referenced by nidas::core::NidasAppArg::setUsageString(), and nidas::core::NidasAppArg::usage().
|
protectedinherited |
bool nidas::core::NidasAppInputFilesArg::allowFiles |
bool nidas::core::NidasAppInputFilesArg::allowSockets |
|
private |
Referenced by nidas::core::NidasApp::parseInputs(), setDefaultInput(), and updateUsage().
|
private |
Referenced by nidas::core::NidasApp::parseInputs(), setDefaultInput(), and updateUsage().