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
4a5e68b6
Commit
4a5e68b6
authored
May 12, 2015
by
Matthias Vallentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug in option parser with single option
Closes #295.
parent
124b2926
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
libcaf_core/src/message.cpp
libcaf_core/src/message.cpp
+9
-6
libcaf_core/test/message.cpp
libcaf_core/test/message.cpp
+9
-2
No files found.
libcaf_core/src/message.cpp
View file @
4a5e68b6
...
...
@@ -226,6 +226,7 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
insert_opt_name
(
i
->
second
);
return
none
;
}
// no value given, try two-argument form below
return
skip_message
();
}
insert_opt_name
(
i
->
second
);
...
...
@@ -257,14 +258,16 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
if
(
arg1
.
size
()
<
2
||
arg1
[
0
]
!=
'-'
||
arg1
[
1
]
==
'-'
)
{
return
skip_message
();
}
auto
i
=
shorts
.
find
(
arg1
);
auto
i
=
shorts
.
find
(
arg1
.
substr
(
0
,
2
)
);
if
(
i
!=
shorts
.
end
())
{
if
(
!
i
->
second
->
fun
)
{
// this short opt does not expect an argument,
// tell extract to try this option again with on
e
// less argument
if
(
i
->
second
->
fun
)
{
if
(
arg1
.
size
()
>
2
)
{
// this short opt comes with a value (no space), e.g., -x2, so w
e
// have to parse it with the one-argument form above
return
skip_message
();
}
CAF_ASSERT
(
arg1
.
size
()
==
2
);
}
if
(
!
i
->
second
->
fun
(
arg2
))
{
error
=
"invalid value for option "
+
i
->
second
->
name
+
": "
+
arg2
;
return
none
;
...
...
libcaf_core/test/message.cpp
View file @
4a5e68b6
...
...
@@ -95,17 +95,24 @@ CAF_TEST(extract3) {
CAF_TEST
(
extract_opts
)
{
auto
f
=
[](
std
::
vector
<
std
::
string
>
xs
)
{
std
::
string
filename
;
size_t
log_level
;
auto
res
=
message_builder
(
xs
.
begin
(),
xs
.
end
()).
extract_opts
({
{
"version,v"
,
"print version"
},
{
"log-level,l"
,
"set the log level"
,
log_level
},
{
"file,f"
,
"set output file"
,
filename
},
{
"whatever"
,
"do whatever"
}
});
CAF_CHECK_EQUAL
(
res
.
opts
.
count
(
"file"
),
1
);
CAF_CHECK_EQUAL
(
to_string
(
res
.
remainder
),
to_string
(
message
{}));
CAF_CHECK_EQUAL
(
filename
,
"hello.txt"
);
CAF_CHECK_EQUAL
(
log_level
,
5
);
};
f
({
"--file=hello.txt"
});
f
({
"-f"
,
"hello.txt"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
});
f
({
"-f"
,
"hello.txt"
,
"--log-level=5"
});
f
({
"-f"
,
"hello.txt"
,
"-l"
,
"5"
});
f
({
"-f"
,
"hello.txt"
,
"-l5"
});
f
({
"-fhello.txt"
,
"-l"
,
"5"
});
f
({
"-l5"
,
"-fhello.txt"
});
}
CAF_TEST
(
type_token
)
{
...
...
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