FreeNOS
ArgumentParser.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBAPP_ARGUMENTPARSER_H
19#define __LIBAPP_ARGUMENTPARSER_H
20
21#include <Types.h>
22#include <Macros.h>
23#include <String.h>
24#include <HashTable.h>
25#include <Vector.h>
26#include "Argument.h"
27#include "ArgumentContainer.h"
28
41{
42 public:
43
54
55 public:
56
61
65 virtual ~ArgumentParser();
66
72 String getUsage() const;
73
79 const String & name() const;
80
86 void setName(const char *name);
87
93 void setDescription(const String & desc);
94
104 Result registerFlag(char arg,
105 const char *name,
106 const char *description);
107
117 Result registerPositional(const char *name,
118 const char *description,
119 Size count = 1);
120
133 Result parse(int argc,
134 char **argv,
135 ArgumentContainer & output);
136
137 private:
138
141
144
147
150
153};
154
160#endif /* __LIBAPP_ARGUMENTPARSER_H */
Generic command-line argument parser.
Generic command-line argument parser.
Result
Result codes.
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.
Efficient key -> value lookups.
Definition HashTable.h:45
Abstraction of strings.
Definition String.h:42
Vectors are dynamically resizeable Arrays.
Definition Vector.h:42
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128