最后代码优化成了这样,先暂时用着。
```c++
int main(int argc, char **argv) {
auto [mainCli, beforeSubcommand] = makeCli(argc);
const auto subcommands = {
serve(),
readData(),
writeData(),
setBaudRate(),
clearAutoResponse(),
getAutoResponse(),
addAutoResponse(),
clearTimedResponse(),
getTimedResponse(),
addTimedResponse(),
get12vStatus(),
set12vStatus(),
getFpgaVersion(),
updateFpga(),
};
unordered_map<App *, function<void()>> subcommandMap;
for (const auto &[cli, callback] : subcommands) {
mainCli->add_subcommand(cli);
subcommandMap.emplace(&*cli, callback);
}
CLI11_PARSE(*mainCli, argc, argv);
beforeSubcommand();
for (auto *key : mainCli->get_subcommands()) {
subcommandMap[key]();
}
return 0;
}
```
```c++
compose(
newCli,
serve,
readData,
setBaudRate,
);
```
```c++
cli.map(serve)
.map(readData)
.map(setBaudRate);
```