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
225907d3
Commit
225907d3
authored
Oct 01, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support unquoted atoms on the CLI
parent
cb4f6977
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
libcaf_core/src/config_option_set.cpp
libcaf_core/src/config_option_set.cpp
+14
-2
libcaf_core/test/config_option_set.cpp
libcaf_core/test/config_option_set.cpp
+21
-0
No files found.
libcaf_core/src/config_option_set.cpp
View file @
225907d3
...
...
@@ -144,8 +144,20 @@ auto config_option_set::parse(config_map& config, argument_iterator first,
auto
val
=
config_value
::
parse
(
slice
);
if
(
!
val
)
return
pec
::
illegal_argument
;
if
(
opt
.
check
(
*
val
)
!=
none
)
return
pec
::
type_mismatch
;
if
(
opt
.
check
(
*
val
)
!=
none
)
{
// The parser defaults to unescaped strings. For example, --foo=bar
// will interpret `bar` as a string. Hence, we'll get a type mismatch
// if `foo` expects an atom. We check this special case here to avoid
// the clumsy --foo="'bar'" notation on the command line.
if
(
holds_alternative
<
std
::
string
>
(
*
val
)
&&
opt
.
type_name
()
==
"atom"
&&
slice
.
substr
(
0
,
1
)
!=
"
\"
"
&&
slice
.
size
()
<=
10
)
{
*
val
=
atom_from_string
(
std
::
string
{
slice
.
begin
(),
slice
.
end
()});
}
else
{
return
pec
::
type_mismatch
;
}
}
opt
.
store
(
*
val
);
submap
[
opt_name
]
=
std
::
move
(
*
val
);
}
...
...
libcaf_core/test/config_option_set.cpp
View file @
225907d3
...
...
@@ -114,4 +114,25 @@ CAF_TEST(implicit global) {
CAF_CHECK_EQUAL
(
get_or
(
cfg
,
"global.help"
,
false
),
true
);
}
CAF_TEST
(
atom
parameters
)
{
opts
.
add
<
atom_value
>
(
"global"
,
"value,v"
);
CAF_MESSAGE
(
"test atom option without quotes"
);
auto
parse_args
=
[
&
](
std
::
vector
<
std
::
string
>
args
)
->
expected
<
atom_value
>
{
dictionary
<
config_value
::
dictionary
>
cfg
;
auto
res
=
opts
.
parse
(
cfg
,
std
::
move
(
args
));
if
(
res
.
first
!=
pec
::
success
)
return
res
.
first
;
auto
atm
=
get_if
<
atom_value
>
(
&
cfg
,
"global.value"
);
if
(
atm
==
none
)
return
sec
::
invalid_argument
;
return
*
atm
;
};
CAF_CHECK_EQUAL
(
parse_args
({
"-v"
,
"'foobar'"
}),
atom
(
"foobar"
));
CAF_CHECK_EQUAL
(
parse_args
({
"-v'foobar'"
}),
atom
(
"foobar"
));
CAF_CHECK_EQUAL
(
parse_args
({
"--value='foobar'"
}),
atom
(
"foobar"
));
CAF_CHECK_EQUAL
(
parse_args
({
"-v"
,
"foobar"
}),
atom
(
"foobar"
));
CAF_CHECK_EQUAL
(
parse_args
({
"-vfoobar"
}),
atom
(
"foobar"
));
CAF_CHECK_EQUAL
(
parse_args
({
"--value=foobar"
}),
atom
(
"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