61 usage <<
"\r\n Positional Arguments:\r\n\r\n";
72 usage <<
"\r\n Optional Arguments:\r\n\r\n";
77 char tmp[2] = { it.current()->getIdentifier(), 0 };
79 (
usage <<
" -" << tmp <<
", --" << it.current()->getName()).pad(16) <<
80 " " << it.current()->getDescription() <<
"\r\n";
102 const char *description)
120 const char *description,
146 for (
int i = 1; i < argc; i++)
150 String & part1 = parts[0];
156 if (part1.
length() > 1 && part1[0] ==
'-' && part1[1] ==
'-')
169 outarg =
new Argument((*arg)->getName());
174 else if (part1.
length() > 1 && part1[0] ==
'-' && part1[1] !=
'-')
192 outarg =
new Argument((*arg)->getName());
Generic command-line argument parser.
Result addPositional(Argument *arg)
Add positional argument.
const Vector< Argument * > & getPositionals() const
Get positional arguments.
Result addFlag(Argument *arg)
Add flag argument.
void setDescription(const String &desc)
Set program description.
Result registerPositional(const char *name, const char *description, Size count=1)
Register a positional argument.
String getUsage() const
Get program usage.
String m_name
Program name.
const String & name() const
Retrieve program name.
Vector< Argument * > m_positionals
Contains all registered positional arguments.
HashTable< String, Argument * > m_flags
Contains all registered flag arguments by name.
String m_description
Program description.
Result parse(int argc, char **argv, ArgumentContainer &output)
Parse input arguments.
HashTable< String, Argument * > m_flagsId
Contains all registered flag arguments by single character identifier.
void setName(const char *name)
Set program name.
virtual ~ArgumentParser()
Destructor.
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
ArgumentParser()
Constructor.
Represents program command line argument.
void setCount(Size count)
Set argument maximum count.
void setIdentifier(char id)
Set argument identifier.
void setDescription(const char *description)
Set argument single line description.
Size getCount() const
Retrieve maximum argument count (if set)
void setValue(const char *value)
Set argument option value.
Iterate through a constant (read-only) HashTable.
virtual bool hasCurrent() const
Check if there is a current item.
Iterate through a HashTable.
virtual bool hasCurrent() const
Check if there is a current item.
virtual const V * get(const K &key) const
Returns the first value for the given key.
virtual Size count() const
Get the number of values stored in the HashTable.
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
Simple linked list template class.
T last()
Get the last value on the list.
virtual int remove(T value)
Remove all items with the given value.
String substring(const Size index, const Size size=0) const
Returns a part of the String as a copy.
Size length() const
Same as count().
List< String > split(const char delimiter) const
Split the String into parts separated by a delimiter.
virtual const T & at(Size position) const
Return item at the given position as a reference.
virtual int insert(const T &item)
Adds the given item to the Vector, if possible.
virtual Size count() const
Returns the number of items inside the Vector.
unsigned int Size
Any sane size indicator cannot go negative.