8000 Question - Using subcommand multiple times with optional arguments · Issue #1119 · CLIUtils/CLI11 · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - Using subcommand multiple times with optional arguments #1119

Open
lambtonr opened this issue Feb 19, 2025 · 1 comment
Open

Question - Using subcommand multiple times with optional arguments #1119

lambtonr opened this issue Feb 19, 2025 · 1 comment

Comments

@lambtonr
Copy link

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",
7CD7
 "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

@phlptp
Copy link
Collaborator
phlptp commented Feb 21, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0