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
97387a6f
Commit
97387a6f
authored
Aug 08, 2015
by
Matthias Vallentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not consume input when extract_opts fails
Resolves #332.
parent
602837e0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
libcaf_core/src/message.cpp
libcaf_core/src/message.cpp
+6
-6
libcaf_core/test/message.cpp
libcaf_core/test/message.cpp
+18
-0
No files found.
libcaf_core/src/message.cpp
View file @
97387a6f
...
...
@@ -273,7 +273,7 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// this short opt comes with a value (no space), e.g., -x2
if
(
!
i
->
second
->
fun
(
arg
.
substr
(
2
)))
{
error
=
"invalid value for "
+
i
->
second
->
name
+
": "
+
arg
;
return
none
;
return
skip_message
()
;
}
insert_opt_name
(
i
->
second
);
return
none
;
...
...
@@ -290,11 +290,11 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
if
(
j
->
second
->
fun
)
{
if
(
eq_pos
==
std
::
string
::
npos
)
{
error
=
"missing argument to "
+
arg
;
return
none
;
return
skip_message
()
;
}
if
(
!
j
->
second
->
fun
(
arg
.
substr
(
eq_pos
+
1
)))
{
error
=
"invalid value for "
+
j
->
second
->
name
+
": "
+
arg
;
return
none
;
return
skip_message
()
;
}
insert_opt_name
(
j
->
second
);
return
none
;
...
...
@@ -303,7 +303,7 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
return
none
;
}
error
=
"unknown command line option: "
+
arg
;
return
none
;
return
skip_message
()
;
},
[
&
](
const
std
::
string
&
arg1
,
const
std
::
string
&
arg2
)
->
optional
<
skip_message_t
>
{
...
...
@@ -321,13 +321,13 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
CAF_ASSERT
(
arg1
.
size
()
==
2
);
if
(
!
i
->
second
->
fun
(
arg2
))
{
error
=
"invalid value for option "
+
i
->
second
->
name
+
": "
+
arg2
;
return
none
;
return
skip_message
()
;
}
insert_opt_name
(
i
->
second
);
return
none
;
}
error
=
"unknown command line option: "
+
arg1
;
return
none
;
return
skip_message
()
;
}
});
return
{
res
,
std
::
move
(
opts
),
std
::
move
(
helpstr
),
std
::
move
(
error
)};
...
...
libcaf_core/test/message.cpp
View file @
97387a6f
...
...
@@ -101,6 +101,24 @@ CAF_TEST(extract_opts) {
f
({
"-f"
,
"hello.txt"
,
"-l5"
});
f
({
"-fhello.txt"
,
"-l"
,
"5"
});
f
({
"-l5"
,
"-fhello.txt"
});
CAF_MESSAGE
(
"ensure that failed parsing doesn't consume input"
);
auto
msg
=
make_message
(
"-f"
,
"42"
,
"-b"
,
"1337"
);
auto
foo
=
0
;
auto
bar
=
0
;
auto
r
=
msg
.
extract_opts
({
{
"foo,f"
,
"foo desc"
,
foo
}
});
CAF_CHECK
(
r
.
opts
.
count
(
"foo"
)
>
0
);
CAF_CHECK
(
foo
==
42
);
CAF_CHECK
(
bar
==
0
);
CAF_CHECK
(
!
r
.
error
.
empty
());
// -b is an unknown option
CAF_CHECK
(
!
r
.
remainder
.
empty
()
&&
r
.
remainder
==
make_message
(
"-b"
,
"1337"
));
r
=
r
.
remainder
.
extract_opts
({
{
"bar,b"
,
"bar desc"
,
bar
}
});
CAF_CHECK
(
r
.
opts
.
count
(
"bar"
)
>
0
);
CAF_CHECK
(
bar
==
1337
);
CAF_CHECK
(
r
.
error
.
empty
());
}
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