MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / parse

Method parse

lib/po/argument_parser.cpp:13–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace PO {
12
13cxx20::expected<bool, Error> ArgumentParser::SubCommandDescriptor::parse(
14 std::FILE *Out, Span<const char *> ProgramNamePrefix, int Argc,
15 const char *Argv[], int ArgP, const bool &VersionOpt) noexcept {
16 ProgramNames.reserve(ProgramNamePrefix.size() + 1);
17 ProgramNames.assign(ProgramNamePrefix.begin(), ProgramNamePrefix.end());
18 if (ArgP < Argc) {
19 ProgramNames.push_back(Argv[ArgP]);
20 }
21 ArgumentDescriptor *CurrentDesc = nullptr;
22 bool FirstNonOption = true;
23 bool Escaped = false;
24 auto PositionalIter = PositionalList.cbegin();
25 for (int ArgI = ArgP + 1; ArgI < Argc; ++ArgI) {
26 std::string_view Arg = Argv[ArgI];
27 if (!Escaped && Arg.size() >= 2 && Arg[0] == '-') {
28 if (Arg[1] == '-') {
29 if (Arg.size() == 2) {
30 Escaped = true;
31 } else {
32 // long option
33 if (CurrentDesc && CurrentDesc->nargs() == 0) {
34 CurrentDesc->default_value();
35 }
36 if (auto Res = consume_long_option_with_argument(Arg); !Res) {
37 return cxx20::unexpected(Res.error());
38 } else {
39 CurrentDesc = *Res;
40 }
41 }
42 } else {
43 // short options
44 if (CurrentDesc && CurrentDesc->nargs() == 0) {
45 CurrentDesc->default_value();
46 }
47 if (auto Res = consume_short_options(Arg); !Res) {
48 return cxx20::unexpected(Res.error());
49 } else {
50 CurrentDesc = *Res;
51 }
52 }
53 } else if (!Escaped && CurrentDesc) {
54 if (auto Res = consume_argument(*CurrentDesc, Arg); !Res) {
55 return cxx20::unexpected(Res.error());
56 }
57 CurrentDesc = nullptr;
58 } else {
59 // no more options
60 if (FirstNonOption) {
61 FirstNonOption = false;
62 if (!SubCommandMap.empty()) {
63 if (auto Iter = SubCommandMap.find(Arg);
64 Iter != SubCommandMap.end()) {
65 auto &Child = this[Iter->second];
66 Child.SC->select();
67 return Child.parse(Out, ProgramNames, Argc, Argv, ArgI, VersionOpt);
68 }
69 }
70 }

Callers 11

FuzzPOFunction · 0.45
WasiNNRPCServerFunction · 0.45
UniToolFunction · 0.45
setInputFunction · 0.45
loadFunction · 0.45
parseRunConfigFunction · 0.45
setInputFunction · 0.45
computeFunction · 0.45
parseMetadataFunction · 0.45
parseMetadataFunction · 0.45
parseMetadataFunction · 0.45

Calls 14

unexpectedClass · 0.85
helpFunction · 0.85
printFunction · 0.85
assignMethod · 0.80
default_valueMethod · 0.80
selectMethod · 0.80
frontMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected