FlagManager.hpp
This file contains tools for dealing with command-line flags (from argv and argc).
The FlagManager class will take command line arguments (either in its constructor or with the AddFlags() function) and process them appropriately.
For setup, the user must run AddOption with the function to call. Functions to call can take zero, one, or two Strings as arguments OR they can take a vector of Strings and the range of allowed arguments should be specified. When Process() is run, the appropriate function will be called on each and any invalid arguments will trigger an error.
Flags are expected to begin with a ‘-’ and non-flags are expected to NOT begin with a ‘-‘.
If a single dash is followed by multiple characters, each will be processed independently. So, “-abc” will be the same as “-a -b -c”.
Extra command line arguments will be saves as a vector of strings called “extras” and must be processed manually. They can be retrieved with GetExtras().
- Todo:
: Make variable numbers of flag arguments work.
Note
Status: ALPHA
-
class FlagManager
- #include <FlagManager.hpp>
Public Functions
-
inline FlagManager()
-
inline FlagManager(int argc, char *argv[])
-
inline void AddOption(String name, std::function<void(const vector<String>&)> fun, size_t min_args = 0, size_t max_args = npos, String desc = "")
-
template<typename FUN_T>
inline void AddOption(char shortcut, String name, FUN_T fun, String desc = "")
-
inline void AddFlags(int argc, char *argv[])
-
inline size_t ProcessArg(char c, size_t cur_pos = 0)
-
inline void Process()
Public Static Attributes
-
static constexpr size_t npos = static_cast<size_t>(-1)
Private Members
-
struct FlagInfo
-
inline FlagManager()