Scarab
v2.4.5
Project 8 C++ Utility Library
library
test
test_app_with_subcommands.cc
Go to the documentation of this file.
1
/*
2
* test_app_with_subcommands.cc
3
*
4
* Created on: Jul 24, 2018
5
* Author: N.S. Oblath
6
* Output examples:
7
*
8
> bin/test_app_with_subcommands
9
10
A subcommand is required
11
Run with --help for more information.
12
13
14
> bin/test_app_with_subcommands get
15
16
2018-07-24 14:06:45 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(92): Final configuration:
17
18
{
19
}
20
21
2018-07-24 14:06:45 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(93): Ordered args:
22
23
[
24
]
25
26
2018-07-24 14:06:45 [ PROG] (tid 0x7fff9c9dc380) h_subcommands.cc(65): Value is: 5
27
28
29
> bin/test_app_with_subcommands set value=10
30
31
2018-07-24 14:06:59 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(92): Final configuration:
32
33
{
34
value : 10
35
}
36
37
2018-07-24 14:06:59 [ PROG] (tid 0x7fff9c9dc380) i/application.cc(93): Ordered args:
38
39
[
40
]
41
42
2018-07-24 14:06:59 [ PROG] (tid 0x7fff9c9dc380) h_subcommands.cc(72): Just to check: 10
43
44
*
45
*/
46
47
48
#include "
application.hh
"
49
50
#include "
logger.hh
"
51
52
LOGGER
( testlog,
"test_app_with_subcommands"
);
53
54
namespace
scarab
55
{
56
struct
get_or_set
57
{
58
get_or_set
() :
f_value
( 5 ) {}
59
60
void
setup_subcommands
(
main_app
& an_app )
61
{
62
app
* t_sc_get = an_app.add_subcommand(
"get"
,
"Get the value"
);
63
t_sc_get->callback([
this
]() { this->
get
(); } );
64
65
app
* t_sc_set = an_app.add_subcommand(
"set"
,
"Set the value"
);
66
t_sc_set->callback([&an_app,
this
]() { this->
set
( an_app ); } );
67
68
return
;
69
}
70
71
void
get
()
72
{
73
LPROG
( testlog,
"Value is: "
<<
f_value
);
74
return
;
75
}
76
77
void
set
(
const
main_app
& an_app )
78
{
79
f_value
= an_app.master_config().get_value(
"value"
,
f_value
);
80
LPROG
( testlog,
"Just to check: "
<<
f_value
);
81
return
;
82
}
83
84
int
f_value
;
85
};
86
}
87
88
89
using namespace
scarab
;
90
91
int
main
(
int
argc,
char
**argv )
92
{
93
main_app
the_main;
94
the_main.require_subcommand();
95
the_main.fallthrough();
96
97
get_or_set
t_gos;
98
t_gos.
setup_subcommands
( the_main );
99
100
CLI11_PARSE( the_main, argc, argv );
101
102
return
0;
103
}
main
int main(int argc, char **argv)
Definition:
test_app_with_subcommands.cc:91
LOGGER
LOGGER(testlog, "test_app_with_subcommands")
scarab::app
CLI::App app
Definition:
application.hh:18
LPROG
#define LPROG(...)
Definition:
logger.hh:363
scarab
Definition:
authentication.cc:18
logger.hh
Contains the logger class and macros, based on Kasper's KLogger class.
scarab::get_or_set::f_value
int f_value
Definition:
test_app_with_subcommands.cc:84
application.hh
scarab::get_or_set::setup_subcommands
void setup_subcommands(main_app &an_app)
Definition:
test_app_with_subcommands.cc:60
scarab::get_or_set
Definition:
test_app_with_subcommands.cc:56
scarab::main_app
Primary application class.
Definition:
application.hh:247
scarab::get_or_set::get_or_set
get_or_set()
Definition:
test_app_with_subcommands.cc:58
Generated by
1.8.13