MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / parse

Method parse

encrypt-config/ArgParser.cpp:120–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120Arguments Arguments::parse(int argc, char* argv[]) {
121 Arguments args;
122 for (int argIdx = 1; argIdx < argc; ++argIdx) {
123 std::string key{argv[argIdx]};
124 if (getFlag(key)) {
125 args.set(key);
126 continue;
127 }
128 if (!getArg(key)) {
129 throw CommandException("Unrecognized option: \"" + key + "\"");
130 }
131 if (argIdx == argc - 1) {
132 throw CommandException("No value specified for key \"" + key + "\"");
133 }
134 ++argIdx;
135 std::string value{argv[argIdx]};
136 args.set(key, value);
137 }
138 if (args.isSet("-h")) {
139 std::cout << getHelp();
140 std::exit(0);
141 }
142 for (const auto& arg : registered_args_) {
143 if (arg.required && !args.get(arg)) {
144 throw CommandException("Missing required option " + utils::StringUtils::join("|", arg.names));
145 }
146 }
147 return args;
148}
149
150utils::optional<Flag> Arguments::getFlag(const std::string &name) {
151 for (const auto& flag : registered_flags_) {

Callers

nothing calls this directly

Calls 4

CommandExceptionClass · 0.85
isSetMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected