Skip to content

Commit bc80a13

Browse files
committed
Accept command arguments as array views
1 parent 700d90c commit bc80a13

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

include/stdcorelib/support/commandline.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,14 +1537,14 @@ namespace stdc::cli {
15371537
/// does not walk the tree before parsing.
15381538
/// \note A program whose command tree is built dynamically, such as from plugins,
15391539
/// should call validate() explicitly before this even in a release build.
1540-
inline ParseResult parse(const std::vector<std::string> &args,
1540+
inline ParseResult parse(array_view<std::string> args,
15411541
ParseOptions parseOptions = Standard) const {
15421542
assert(!validate(parseOptions).has_value() && "the command tree is invalid");
15431543
return parseImpl(args, parseOptions);
15441544
}
15451545
/// Parses and does everything a \c main does with the answer, reporting a failure and
15461546
/// answering a Help or Version option before any handler runs. \sa ParseResult::invoke()
1547-
inline int invoke(const std::vector<std::string> &args, int errorCode = -1,
1547+
inline int invoke(array_view<std::string> args, int errorCode = -1,
15481548
ParseOptions parseOptions = Standard) const {
15491549
return parse(args, parseOptions).invoke(errorCode);
15501550
}
@@ -1565,8 +1565,7 @@ namespace stdc::cli {
15651565
}
15661566

15671567
private:
1568-
ParseResult parseImpl(const std::vector<std::string> &args,
1569-
ParseOptions parseOptions) const;
1568+
ParseResult parseImpl(array_view<std::string> args, ParseOptions parseOptions) const;
15701569

15711570
class Impl;
15721571
std::unique_ptr<Impl> _impl;

src/support/commandline.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ namespace stdc::cli {
11131113
ParserCore(detail::parse_data *out, Parser::ParseOptions flags) : r(out), flags(flags) {
11141114
}
11151115

1116-
void run(const std::vector<std::string> &args);
1116+
void run(array_view<std::string> args);
11171117

11181118
private:
11191119
using Error = ParseResult::Error;
@@ -1799,7 +1799,7 @@ namespace stdc::cli {
17991799
}
18001800
}
18011801

1802-
void ParserCore::run(const std::vector<std::string> &args) {
1802+
void ParserCore::run(array_view<std::string> args) {
18031803
// The first argument names the program rather than anything to parse.
18041804
tokens.assign(args.begin() + (args.empty() ? 0 : 1), args.end());
18051805
if (on(Parser::EnableResponseFile)) {
@@ -1999,8 +1999,7 @@ namespace stdc::cli {
19991999
parseOptions.test_flag(IgnoreCommandCase));
20002000
}
20012001

2002-
ParseResult Parser::parseImpl(const std::vector<std::string> &args,
2003-
ParseOptions parseOptions) const {
2002+
ParseResult Parser::parseImpl(array_view<std::string> args, ParseOptions parseOptions) const {
20042003
stdc_impl_t;
20052004
ParseResult result;
20062005
auto &out = *result._impl;

tests/auto/support/test_commandline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3+
#include <array>
34
#include <cmath>
45
#include <cstdint>
56
#include <cstdio>

0 commit comments

Comments
 (0)