MCPcopy Create free account
hub / github.com/Beckhoff/ADS / ParseCommand

Function ParseCommand

AdsTest/main.cpp:66–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64}
65
66int ParseCommand(int argc, const char *argv[])
67{
68 auto args = bhf::Commandline{ usage, argc, argv };
69
70 // drop argv[0] program name
71 args.Pop<const char *>();
72
73 const auto str = args.Pop<const char *>("Target is missing");
74 if (!strcmp("--help", str)) {
75 usage();
76 }
77
78 const auto split = std::strcspn(str, ":");
79 const auto netId = std::string{ str, split };
80 const auto port = bhf::try_stoi<uint16_t>(str + split);
81 LOG_VERBOSE("NetId>" << netId << "< port>" << port << "<\n");
82
83 bhf::ParameterList global = {
84 { "--gw" },
85 { "--localams" },
86 { "--log-level" },
87 };
88 args.Parse(global);
89
90 const auto localNetId = global.Get<std::string>("--localams");
91 if (!localNetId.empty()) {
92 bhf::ads::SetLocalAddress(make_AmsNetId(localNetId));
93 }
94
95 const auto logLevel = global.Get<size_t>("--log-level", 1);
96 // highest loglevel is error==3, we allow 4 to disable all messages
97 Logger::logLevel = std::min(logLevel, (size_t)4);
98
99 const auto cmd = args.Pop<const char *>("Command is missing");
100
101 const auto commands = CommandMap{
102 { "registry", RunRegistry },
103 };
104 const auto it = commands.find(cmd);
105 if (it != commands.end()) {
106 return it->second(make_AmsNetId(netId), port,
107 global.Get<std::string>("--gw"), args);
108 }
109 usage(std::string{ "Unknown command >" } + cmd + "<\n");
110
111 return 0;
112}
113
114int main(int argc, const char *argv[])
115{

Callers 1

mainFunction · 0.70

Calls 4

make_AmsNetIdFunction · 0.85
usageFunction · 0.70
SetLocalAddressFunction · 0.50
ParseMethod · 0.45

Tested by

no test coverage detected