Leonetienne/Hazelnupp
Simple, easy to use, command line parameter interface
Hazelnupp
main.cpp
Go to the documentation of this file.
1
#include <iostream>
2
#include "
Hazelnupp.h
"
3
#include "
IntValue.h
"
4
5
using namespace
Hazelnp
;
6
7
int
main
(
int
argc,
char
** argv)
8
{
9
while
(1)
10
{
11
// Mock command-line params
12
std::vector<const char*> testArgv = {
13
"meinpfad"
,
14
"-w"
,
15
"-99"
,
16
"--alfred"
,
17
"apfel"
,
18
"banane"
,
19
"triangle"
,
20
"--numbers"
,
21
"1"
,
22
"2"
,
23
"3"
,
24
"4"
,
25
"5"
,
26
};
27
28
argc = testArgv.size();
29
argv =
const_cast<
char
**
>
(testArgv.data());
30
31
// Prepare Hazelnupp parser
32
Hazelnupp
args;
33
34
ParamConstraint
pc;
35
pc.
key
=
"--alfredo"
;
36
pc.
constrainType
=
true
;
37
pc.
wantedType
=
DATA_TYPE::LIST
;
38
pc.
required
=
true
;
39
pc.
defaultValue
= {
"coca cola"
,
"fanta"
};
40
41
args.
RegisterConstraints
({
42
pc
43
});
44
45
args.
RegisterAbbreviation
(
"-w"
,
"--word"
);
46
47
// Parse
48
args.
Parse
(argc, argv);
49
50
// Use
51
if
(args.
HasParam
(
"--alfredo"
))
52
{
53
std::cout << args[
"--alfredo"
].GetInt32() << std::endl;
54
}
55
else
56
{
57
std::cout <<
"No --alfredo!"
<< std::endl;
58
}
59
}
60
61
return
0;
62
}
Hazelnp
Definition:
DataType.h:3
Hazelnp::Hazelnupp
The main class to interface with.
Definition:
Hazelnupp.h:11
IntValue.h
main
int main(int argc, char **argv)
Definition:
main.cpp:7
Hazelnp::DATA_TYPE::LIST
@ LIST
Hazelnp::ParamConstraint::wantedType
DATA_TYPE wantedType
Constrain the parameter to this value. Requires constrainType to be set to true.
Definition:
ParamConstraint.h:57
Hazelnp::ParamConstraint
Definition:
ParamConstraint.h:8
Hazelnp::Hazelnupp::HasParam
bool HasParam(const std::string &key) const
Will check wether a parameter exists given a key, or not.
Definition:
Hazelnupp.cpp:153
Hazelnp::Hazelnupp::Parse
void Parse(const int argc, const char *const *argv)
Will parse command line arguments.
Definition:
Hazelnupp.cpp:35
Hazelnp::ParamConstraint::constrainType
bool constrainType
Should this parameter be forced to be of a certain type? Remember to set constrainTo to the wanted ...
Definition:
ParamConstraint.h:54
Hazelnp::Hazelnupp::RegisterAbbreviation
void RegisterAbbreviation(const std::string &abbrev, const std::string &target)
Will register an abbreviation (like -f for –force)
Definition:
Hazelnupp.cpp:332
Hazelnp::Hazelnupp::RegisterConstraints
void RegisterConstraints(const std::vector< ParamConstraint > &constraints)
Will register parameter constraints.
Definition:
Hazelnupp.cpp:354
Hazelnupp.h
Hazelnp::ParamConstraint::key
std::string key
The key of the parameter to constrain.
Definition:
ParamConstraint.h:50
Hazelnp::ParamConstraint::required
bool required
If set to true, and no default value set, an error will be produced if this parameter is not supplied...
Definition:
ParamConstraint.h:66
Hazelnp::ParamConstraint::defaultValue
std::vector< std::string > defaultValue
The default value for this parameter.
Definition:
ParamConstraint.h:62
Generated on Thu Jun 3 2021 13:42:54 for Leonetienne/Hazelnupp by
1.8.17