CLI11
CLI11 copied to clipboard
Question - Using subcommand multiple times with optional arguments
Hi,
I am trying to expand my CLI to allow the user to specify multiple model_ids with optional precision values (defaulted to FP16)
i am trying to do the following:
const std::map<std::string, trt::Precision> precisionmap{
{"fp16", trt::Precision::FP16},
{"fp32", trt::Precision::FP32}};
...
auto* model = app.add_subcommand("model", "Model params")->needs(capture);
std::string modelId {};
trt::Precision precision {trt::Precision::FP16};
model->add_option("-m,--model", modelId, "Model id")->required()->expected(-1);
model->add_option("-p,--precision", precision, "Model precision")
->transform(CLI::CheckedTransformer(precisionmap, CLI::ignore_case))
->option_text("ENUM:value in {FP16|FP32} [FP16]")
->default_val("FP16");
model->callback([&]() {
std::cout << "adding model " << modelId << "with precision " << (precision == trt::Precision::FP16 ? "FP16" : "FP32") << std::endl;
pipeline.model.emplace_back(ModelConfig{modelId, precision});
});
what i am trying to achieve is is the following functionality
./app model -m model_id_1 -p FP32 model -m model_id_2 model -m model_id_3 -p FP32
or
./app model -m model_id_1 -p FP32 -m model_id_2 -m model_id_3 -p FP32
I can get it working if i use a vectorstd::string id, vectortrt::Presision precision and make them both required but allowing the precision as optional misaligns the two vectors.
Many Thanks
Would it be an option to not have the -p part and just have it be -m model_id_1 FP32 -m model_id2 -m model_id3 FP16 Then having them stored to a vector of pairs? If that is an option there are ways of specifying the defaults and keeping things aligned?