29 #ifndef POSIX_APP_CHILICTL_COMMON_ARGS_H_
30 #define POSIX_APP_CHILICTL_COMMON_ARGS_H_
47 using argCallback = std::function<
ca_error(
const char *)>;
48 template <
class T>
using argCallbackMemRaw =
ca_error (T::*)(
const char *argument);
67 ArgOpt(
char aShortArg,
const char *aLongArg,
ArgPerm aArgPerm = ArgPerm::NO_ARG);
79 void SetArgHint(
const char *aArgHint) { arghint = aArgHint; }
85 void SetCallback(argCallback aCallback) { callback = aCallback; }
92 template <
class T>
void SetCallback(argCallbackMemRaw<T> aCallback, T &aInstance)
94 callback = std::bind(aCallback, &aInstance, std::placeholders::_1);
110 argCallback callback;
119 ca_error call_callback(
const char *aArg)
123 return callback(aArg);
139 : mFinalOpt(std::numeric_limits<
int>::max())
182 std::vector<ArgOpt *> mOptions;
189 static bool is_shortopt(
const char *aStr);
196 static bool is_longopt(
const char *aStr);
203 static bool is_end_of_opts(
const char *aStr);
210 static bool is_opt(
const char *aStr);
223 ca_error process_short_opts(
int &argi,
int argc,
const char *argv[]);
236 ca_error process_long_opt(
int &argi,
int argc,
const char *argv[]);
243 void print_longopt_error(
const char *optptr,
size_t optlen);
250 void print_opt_help_string(FILE *out,
ArgOpt *opt);
Global error declarations for use across the Cascoda SDK.
Structure for holding the definition of potential options to pass on the command line.
Definition: Args.hpp:45
ArgPerm
Enumeration for whether or not an option permits/requires arguments.
Definition: Args.hpp:55
@ MANDATORY_ARG
Option requires an argument to be provided.
Definition: Args.hpp:58
@ NO_ARG
No argument allowed to option.
Definition: Args.hpp:56
@ OPTIONAL_ARG
Option has optional argument.
Definition: Args.hpp:57
void SetCallback(argCallbackMemRaw< T > aCallback, T &aInstance)
Set the callback to be called when the option is detected.
Definition: Args.hpp:92
void SetArgHint(const char *aArgHint)
Set the short argument hint string, describing the argument (eg "yes|no", "path", "value)
Definition: Args.hpp:79
ArgOpt(char aShortArg, const char *aLongArg, ArgPerm aArgPerm=ArgPerm::NO_ARG)
Construct an ArgOpt data structure.
Definition: Args.cpp:36
void SetHelpString(const char *aHelpString)
Set the help string of the option.
Definition: Args.hpp:73
int GetCallCount(void)
Get the number of times this option was detected during parsing.
Definition: Args.hpp:101
void SetCallback(argCallback aCallback)
Set the callback to be called when the option is detected.
Definition: Args.hpp:85
Class for parsing and handling options passed as command line arguments.
Definition: Args.hpp:133
Args()
Default constructor, initialises empty arg parser.
Definition: Args.hpp:138
ca_error ProcessOption(int &argi, int argc, const char *argv[])
Process a single option from argv using the provided ArgOpt structures.
Definition: Args.cpp:52
void PrintOptionHelpStrings(FILE *aOutFile)
Print all of the option help strings to the 'out' file pointer in manpage format.
Definition: Args.cpp:80
void AddOption(ArgOpt &aOption)
Add an option definition to this parser.
Definition: Args.hpp:178
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
@ CA_ERROR_SUCCESS
Success.
Definition: ca821x_error.h:53
uint8_t count
Definition: serial-test.c:58