Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (50 loc) · 1.65 KB
/
Copy pathmain.cpp
File metadata and controls
67 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include "justargs.h"
int main( int argc, char * argv[] )
{
/* variables to be used in ths application */
bool help;
bool verbose;
int age;
double height;
std::string name;
/* Contruct justargs class */
justargs cmdline( argc, argv );
/* check if help is present, if so print help and exit */
if( (cmdline.getparameter( help, "-h", "--help" )) < justargsFAIL )
{
std::cout << "This is a not so helpful helpscreen\n";
return 0;
}
/* simples checks */
/* get parameters from command line into variables */
if( (cmdline.getparameter( verbose, "-v", "--verbose" )) != justargsOK )
{
std::cerr << "Parameter verbose not present or of wrong type!\n";
return 1;
}
/* get parameter with only shortname */
if( (cmdline.getparameter( age, "-a", "" )) != justargsOK )
{
std::cerr << "Parameter age not present or of wrong type!\n";
return 1;
}
/* get parameter with only longname */
if( (cmdline.getparameter( name, "", "--name" )) != justargsOK )
{
std::cerr << "Parameter height not present or of wrong type!\n";
return 1;
}
/* get parameter with both long and short names */
if( (cmdline.getparameter( height, "-h", "--height" )) != justargsOK )
{
std::cerr << "Parameter height not present or of wrong type!\n";
return 1;
}
std::cout << "Information given is:\n";
std::cout << " Name: " << name << std::endl;
std::cout << " Age: " << age << std::endl;
if( verbose )
std::cout << " Height: " << height << std::endl;
return 0;
}