Scarab
v2.4.7
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
#include "
application.hh
"
48
49
#include "
logger.hh
"
50
51
LOGGER
( testlog,
"test_app_with_subcommands"
);
52
53
namespace
scarab
54
{
55
struct
get_or_set
56
{
57
get_or_set
() :
f_value
( 5 ) {}
58
59
void
setup_subcommands
(
main_app
& an_app )
60
{
61
app
* t_sc_get = an_app.add_subcommand(
"get"
,
"Get the value"
);
62
t_sc_get->callback([
this
]() { this->
get
(); } );
63
64
app
* t_sc_set = an_app.add_subcommand(
"set"
,
"Set the value"
);
65
t_sc_set->callback([&an_app,
this
]() { this->
set
( an_app ); } );
66
67
return
;
68
}
69
70
void
get
()
71
{
72
LPROG
( testlog,
"Value is: "
<<
f_value
);
73
return
;
74
}
75
76
void
set
(
const
main_app
& an_app )
77
{
78
f_value
= an_app.master_config().get_value(
"value"
,
f_value
);
79
LPROG
( testlog,
"Just to check: "
<<
f_value
);
80
return
;
81
}
82
83
int
f_value
;
84
};
85
}
86
87
88
using namespace
scarab
;
89
90
int
main
(
int
argc,
char
**argv )
91
{
92
main_app
the_main;
93
the_main.require_subcommand();
94
the_main.fallthrough();
95
96
get_or_set
t_gos;
97
t_gos.
setup_subcommands
( the_main );
98
99
CLI11_PARSE( the_main, argc, argv );
100
101
return
0;
102
}
main
int main(int argc, char **argv)
Definition:
test_app_with_subcommands.cc:90
LOGGER
LOGGER(testlog, "test_app_with_subcommands")
scarab::app
CLI::App app
Definition:
application.hh:18
LPROG
#define LPROG(...)
Definition:
logger.hh:368
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:83
application.hh
scarab::get_or_set::setup_subcommands
void setup_subcommands(main_app &an_app)
Definition:
test_app_with_subcommands.cc:59
scarab::get_or_set
Definition:
test_app_with_subcommands.cc:55
scarab::main_app
Primary application class.
Definition:
application.hh:252
scarab::get_or_set::get_or_set
get_or_set()
Definition:
test_app_with_subcommands.cc:57
Generated by
1.8.13