Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
clapp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libclapp
clapp
Commits
52bbf513
Commit
52bbf513
authored
2 years ago
by
Martin Wölzer
Browse files
Options
Downloads
Patches
Plain Diff
examples/short_example.cpp: updated short-example to make use of option-container
parent
b8bd8a70
No related branches found
No related tags found
1 merge request
!22
Add support for option-container
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/short_example.cpp
+33
-15
33 additions, 15 deletions
examples/short_example.cpp
with
33 additions
and
15 deletions
examples/short_example.cpp
+
33
−
15
View file @
52bbf513
...
...
@@ -12,7 +12,7 @@ clapp::value::found_func_t::ret_t print_version_and_exit(
class
cli_parser_t
:
public
clapp
::
basic_main_parser_t
{
public:
cli_parser_t
()
=
default
;
cli_parser_t
();
explicit
cli_parser_t
(
const
cli_parser_t
&
)
=
delete
;
explicit
cli_parser_t
(
cli_parser_t
&&
)
noexcept
=
delete
;
...
...
@@ -45,14 +45,24 @@ class cli_parser_t : public clapp::basic_main_parser_t {
*
this
,
"variadic-string-arg"
,
"Variadic String argument"
,
purpose_t
::
optional
};
// mandatory string option
clapp
::
string_param_option_t
string_param
{
*
this
,
"string"
,
std
::
vector
<
char
>
{
's'
,
'1'
},
"String option 1."
,
purpose_t
::
mandatory
};
class
and_option_container_t
:
public
clapp
::
option_container_t
{
public:
using
clapp
::
option_container_t
::
option_container_t
;
// optional string option (multiple string vectors)
clapp
::
vector_string_param_option_t
string_vector_param
{
*
this
,
"string-vector"
,
"String vector param."
};
~
and_option_container_t
()
override
;
// mandatory string option
clapp
::
string_param_option_t
string_param
{
*
this
,
"string"
,
std
::
vector
<
char
>
{
's'
,
'1'
},
"String option 1."
,
purpose_t
::
mandatory
};
// optional string option (multiple string vectors)
clapp
::
vector_string_param_option_t
string_vector_param
{
*
this
,
"string-vector"
,
"String vector param."
};
};
and_option_container_t
options
{
*
this
,
clapp
::
parser
::
types
::
logic_operator_type_t
::
logic_and
};
};
clapp
::
value
::
found_func_t
::
ret_t
print_version_and_exit
(
...
...
@@ -63,6 +73,12 @@ clapp::value::found_func_t::ret_t print_version_and_exit(
cli_parser_t
::~
cli_parser_t
()
=
default
;
cli_parser_t
::
and_option_container_t
::~
and_option_container_t
()
=
default
;
cli_parser_t
::
cli_parser_t
()
:
clapp
::
basic_main_parser_t
{
clapp
::
parser
::
types
::
logic_operator_type_t
::
logic_xor
}
{}
using
parser_t
=
clapp
::
parser
::
basic_parser_container_t
<
cli_parser_t
>
;
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -95,16 +111,18 @@ int main(int argc, char *argv[]) {
std
::
cout
<<
"variadic-string-arg: not given"
<<
std
::
endl
;
}
Expects
(
parser
->
string_param
);
// The parser ensures that
// mandatory options are given
std
::
cout
<<
"string_param: '"
<<
parser
->
string_param
.
value
()
<<
"'"
<<
std
::
endl
;
Expects
(
parser
->
options
.
string_param
);
// The parser ensures that
// mandatory options are given
std
::
cout
<<
"string_param: '"
<<
parser
->
options
.
string_param
.
value
()
<<
"'"
<<
std
::
endl
;
if
(
parser
->
string_vector_param
)
{
// if string_vector_param is given
if
(
parser
->
options
.
string_vector_param
)
{
// if string_vector_param is given
std
::
cout
<<
"string_vector_param (size: "
<<
parser
->
string_vector_param
.
value
().
size
()
<<
"): "
;
<<
parser
->
options
.
string_vector_param
.
value
().
size
()
<<
"): "
;
// iterate over the vector of options
for
(
auto
&
val
:
parser
->
string_vector_param
.
value
())
{
for
(
auto
&
val
:
parser
->
options
.
string_vector_param
.
value
())
{
std
::
cout
<<
val
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment