| 840 | |
| 841 | |
| 842 | struct option *SingleCommand::init_getopt() |
| 843 | { |
| 844 | unsigned int idx = 0; |
| 845 | shortopts = ""; |
| 846 | struct option *result = (struct option *)calloc(options.size() + 2, |
| 847 | sizeof(struct option)); |
| 848 | if (result == NULL) |
| 849 | { |
| 850 | throw CommandException(command, "Failed to allocate memory for option parsing"); |
| 851 | } |
| 852 | |
| 853 | // Parse through all registered options |
| 854 | for (auto const &opt : options) |
| 855 | { |
| 856 | // Apply the option definition into the pre-defined designated |
| 857 | // slot |
| 858 | for (const auto &o : opt->get_struct_option()) |
| 859 | { |
| 860 | memcpy(&result[idx], o, sizeof(struct option)); |
| 861 | idx++; |
| 862 | } |
| 863 | |
| 864 | // Collect all we need for the short flags too |
| 865 | shortopts += opt->getopt_optstring(); |
| 866 | } |
| 867 | |
| 868 | // getopt_long() expects the last record in the struct option array |
| 869 | // to be an empty/zeroed struct option element |
| 870 | result[idx] = {0}; |
| 871 | return result; |
| 872 | } |
| 873 | |
| 874 | |
| 875 | std::string SingleCommand::gen_help(const std::string arg0) |
nothing calls this directly
no test coverage detected