| 59 | } |
| 60 | |
| 61 | std::vector<std::string> common_preset::to_args(const std::string & bin_path) const { |
| 62 | std::vector<std::string> args; |
| 63 | |
| 64 | if (!bin_path.empty()) { |
| 65 | args.push_back(bin_path); |
| 66 | } |
| 67 | |
| 68 | for (const auto & [opt, value] : options) { |
| 69 | if (opt.is_preset_only) { |
| 70 | continue; // skip preset-only options (they are not CLI args) |
| 71 | } |
| 72 | |
| 73 | // use the last arg as the main arg (i.e. --long-form) |
| 74 | args.push_back(opt.args.back()); |
| 75 | |
| 76 | // handle value(s) |
| 77 | if (opt.value_hint == nullptr && opt.value_hint_2 == nullptr) { |
| 78 | // flag option, no value |
| 79 | if (common_arg_utils::is_falsey(value)) { |
| 80 | // use negative arg if available |
| 81 | if (!opt.args_neg.empty()) { |
| 82 | args.back() = opt.args_neg.back(); |
| 83 | } else { |
| 84 | // otherwise, skip the flag |
| 85 | // TODO: maybe throw an error instead? |
| 86 | args.pop_back(); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | if (opt.value_hint != nullptr) { |
| 91 | // single value |
| 92 | args.push_back(value); |
| 93 | } |
| 94 | if (opt.value_hint != nullptr && opt.value_hint_2 != nullptr) { |
| 95 | throw std::runtime_error(string_format( |
| 96 | "common_preset::to_args(): option '%s' has two values, which is not supported yet", |
| 97 | opt.args.back() |
| 98 | )); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return args; |
| 103 | } |
| 104 | |
| 105 | std::string common_preset::to_ini() const { |
| 106 | std::ostringstream ss; |
no test coverage detected