Search code examples
rustclap

what is the correct way to get ownership of an argument with clap?


I would like to pass the options of my CLI program via a Config-struct that has ownership of its values, i.e. Strings of paths. The now deprecated ArgMatches::values_of_lossy() returned an owned String, however, ArgMatches::get_many() only returns a ValuesRef<>. What is the best way to get ownership of the argument itself, ideally without cloning?


Solution

  • ArgMatches::remove_many will give you ownership, by moving those values out of the ArgMatches struct.