Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
018144ed
Unverified
Commit
018144ed
authored
Apr 06, 2019
by
Dominik Charousset
Committed by
GitHub
Apr 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #831
Fix nested categories in config options
parents
cfc1e1d6
7dbb23de
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
7 deletions
+37
-7
libcaf_core/src/config_option_set.cpp
libcaf_core/src/config_option_set.cpp
+19
-7
libcaf_core/test/config_option.cpp
libcaf_core/test/config_option.cpp
+9
-0
libcaf_core/test/config_option_set.cpp
libcaf_core/test/config_option_set.cpp
+9
-0
No files found.
libcaf_core/src/config_option_set.cpp
View file @
018144ed
...
...
@@ -115,6 +115,19 @@ std::string config_option_set::help_text(bool global_only) const {
return
std
::
move
(
builder
.
result
);
}
namespace
{
settings
&
select_entry
(
settings
&
config
,
string_view
key
){
auto
sep
=
key
.
find
(
'.'
);
if
(
sep
==
string_view
::
npos
)
return
config
[
key
].
as_dictionary
();
auto
prefix
=
key
.
substr
(
0
,
sep
);
auto
suffix
=
key
.
substr
(
sep
+
1
);
return
select_entry
(
config
[
prefix
].
as_dictionary
(),
suffix
);
}
}
// namespace
auto
config_option_set
::
parse
(
settings
&
config
,
argument_iterator
first
,
argument_iterator
last
)
const
->
std
::
pair
<
pec
,
argument_iterator
>
{
...
...
@@ -128,8 +141,7 @@ auto config_option_set::parse(settings& config, argument_iterator first,
auto
opt_name
=
opt
.
long_name
();
auto
opt_ctg
=
opt
.
category
();
// Try inserting a new submap into the config or fill existing one.
auto
&
entry
=
opt_ctg
==
"global"
?
config
:
config
[
opt_ctg
].
as_dictionary
();
auto
&
entry
=
opt_ctg
==
"global"
?
config
:
select_entry
(
config
,
opt_ctg
);
// Flags only consume the current element.
if
(
opt
.
is_flag
())
{
if
(
arg_begin
!=
arg_end
)
...
...
@@ -223,17 +235,17 @@ config_option_set::parse(settings& config,
}
config_option_set
::
option_pointer
config_option_set
::
cli_long_name_lookup
(
string_view
name
)
const
{
config_option_set
::
cli_long_name_lookup
(
string_view
input
)
const
{
// We accept "caf#" prefixes for backward compatibility, but ignore them.
size_t
offset
=
name
.
compare
(
0
,
4
,
"caf#"
)
!=
0
?
0u
:
4u
;
auto
name
=
input
.
substr
(
input
.
compare
(
0
,
4
,
"caf#"
)
!=
0
?
0u
:
4u
)
;
// Extract category and long name.
string_view
category
;
string_view
long_name
;
auto
sep
=
name
.
find
(
'.'
,
offset
);
auto
sep
=
name
.
find
_last_of
(
'.'
);
if
(
sep
==
string
::
npos
)
{
long_name
=
name
.
substr
(
offset
)
;
long_name
=
name
;
}
else
{
category
=
name
.
substr
(
offset
,
sep
);
category
=
name
.
substr
(
0
,
sep
);
long_name
=
name
.
substr
(
sep
+
1
);
}
// Scan all options for a match.
...
...
libcaf_core/test/config_option.cpp
View file @
018144ed
...
...
@@ -190,3 +190,12 @@ CAF_TEST(flat CLI parsing) {
CAF_CHECK_EQUAL
(
x
.
full_name
(),
"foo.bar"
);
CAF_CHECK_EQUAL
(
x
.
has_flat_cli_name
(),
true
);
}
CAF_TEST
(
flat
CLI
parsing
with
nested
categories
)
{
auto
x
=
make_config_option
<
std
::
string
>
(
"?foo.goo"
,
"bar,b"
,
"test option"
);
CAF_CHECK_EQUAL
(
x
.
category
(),
"foo.goo"
);
CAF_CHECK_EQUAL
(
x
.
long_name
(),
"bar"
);
CAF_CHECK_EQUAL
(
x
.
short_names
(),
"b"
);
CAF_CHECK_EQUAL
(
x
.
full_name
(),
"foo.goo.bar"
);
CAF_CHECK_EQUAL
(
x
.
has_flat_cli_name
(),
true
);
}
libcaf_core/test/config_option_set.cpp
View file @
018144ed
...
...
@@ -151,4 +151,13 @@ CAF_TEST(flat CLI options) {
CAF_CHECK_EQUAL
(
read
<
std
::
string
>
({
"--foo.bar=foobar"
}),
"foobar"
);
}
CAF_TEST
(
flat
CLI
parsing
with
nested
categories
)
{
key
=
"foo.goo.bar"
;
opts
.
add
<
std
::
string
>
(
"?foo.goo"
,
"bar,b"
,
"some value"
);
CAF_CHECK
(
opts
.
begin
()
->
has_flat_cli_name
());
CAF_CHECK_EQUAL
(
read
<
std
::
string
>
({
"-b"
,
"foobar"
}),
"foobar"
);
CAF_CHECK_EQUAL
(
read
<
std
::
string
>
({
"--bar=foobar"
}),
"foobar"
);
CAF_CHECK_EQUAL
(
read
<
std
::
string
>
({
"--foo.goo.bar=foobar"
}),
"foobar"
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment