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
438784fa
Commit
438784fa
authored
Jun 16, 2017
by
Dominik Charousset
Committed by
GitHub
Jun 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #564
Ignore CLI args after --
parents
c931f08d
afdabde4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
libcaf_core/src/message.cpp
libcaf_core/src/message.cpp
+13
-0
libcaf_core/test/message.cpp
libcaf_core/test/message.cpp
+19
-9
No files found.
libcaf_core/src/message.cpp
View file @
438784fa
...
...
@@ -236,8 +236,15 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// we can't `return make_error(...)` from inside `extract`, hence we
// store any occurred error in a temporary variable returned at the end
std
::
string
error
;
bool
skip_remainder
=
false
;
auto
res
=
extract
({
[
&
](
const
std
::
string
&
arg
)
->
optional
<
skip_t
>
{
if
(
arg
==
"--"
)
{
skip_remainder
=
true
;
return
none
;
}
if
(
skip_remainder
)
return
skip
();
if
(
arg
.
empty
()
||
arg
.
front
()
!=
'-'
)
{
return
skip
();
}
...
...
@@ -287,6 +294,12 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
},
[
&
](
const
std
::
string
&
arg1
,
const
std
::
string
&
arg2
)
->
optional
<
skip_t
>
{
if
(
arg1
==
"--"
)
{
skip_remainder
=
true
;
return
skip
();
}
if
(
skip_remainder
)
return
skip
();
if
(
arg1
.
size
()
<
2
||
arg1
[
0
]
!=
'-'
||
arg1
[
1
]
==
'-'
)
{
return
skip
();
}
...
...
libcaf_core/test/message.cpp
View file @
438784fa
...
...
@@ -107,9 +107,9 @@ CAF_TEST(extract2) {
}
CAF_TEST
(
extract_opts
)
{
auto
f
=
[](
std
::
vector
<
std
::
string
>
xs
)
{
auto
f
=
[](
std
::
vector
<
std
::
string
>
xs
,
std
::
vector
<
std
::
string
>
remainder
)
{
std
::
string
filename
;
size_t
log_level
;
size_t
log_level
=
0
;
auto
res
=
message_builder
(
xs
.
begin
(),
xs
.
end
()).
extract_opts
({
{
"version,v"
,
"print version"
},
{
"log-level,l"
,
"set the log level"
,
log_level
},
...
...
@@ -117,16 +117,26 @@ CAF_TEST(extract_opts) {
{
"whatever"
,
"do whatever"
}
});
CAF_CHECK_EQUAL
(
res
.
opts
.
count
(
"file"
),
1u
);
CAF_CHECK
(
res
.
remainder
.
empty
());
CAF_CHECK
(
res
.
remainder
.
size
()
==
remainder
.
size
());
for
(
size_t
i
=
0
;
i
<
res
.
remainder
.
size
()
&&
i
<
remainder
.
size
();
++
i
)
{
CAF_CHECK
(
remainder
[
i
]
==
res
.
remainder
.
get_as
<
string
>
(
i
));
}
CAF_CHECK_EQUAL
(
filename
,
"hello.txt"
);
CAF_CHECK_EQUAL
(
log_level
,
5u
);
};
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"
});
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"
},
{});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"a"
},
{
"a"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"a"
,
"b"
},
{
"a"
,
"b"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"aa"
,
"bb"
},
{
"aa"
,
"bb"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"-a"
,
"--bb"
},
{
"-a"
,
"--bb"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"-a1"
,
"--bb=10"
},
{
"-a1"
,
"--bb=10"
});
f
({
"--file=hello.txt"
,
"-l"
,
"5"
,
"--"
,
"-a 1"
,
"--b=10"
},
{
"-a 1"
,
"--b=10"
});
CAF_MESSAGE
(
"ensure that failed parsing doesn't consume input"
);
auto
msg
=
make_message
(
"-f"
,
"42"
,
"-b"
,
"1337"
);
auto
foo
=
0
;
...
...
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