CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

howto: simulate K V checked args list

Open leaveye opened this issue 1 year ago • 2 comments

i want to write a helper tool to edit configure on my target box.

suppose we have config-entries constants:

# `key1` accept only `value1` and `value2`
key1: value1 value2
key2: foo bar baz

is there a way to let my tool command line like:

set-helper key1 value1 key2 refused

and with param validation works with both key and values?


i have imagined a way that takes vector<string> arg and do check in a sort-of-callback. but seems not fit the CLI11 design principle. any suggestion?

leaveye avatar Sep 15 '24 16:09 leaveye

The simplest way is probably just a custom callback that does some additional checks. You could probably do a stateful validator that does the checks inline, but I think in this case a callback on the app that does the checks would be the simplest choice, then you have access to the entire vector.

phlptp avatar Sep 19 '24 12:09 phlptp

i hv tried that callback way. it did work.

however, sadly, the code looks like i hv no CLI11 imported...

leaveye avatar Apr 26 '25 09:04 leaveye