I want to create an utility that accepts positional arguments like some Linux utilities that accept a variable number of SRC arguments followed by a single DEST argument, with a syntax that is analog to 'cp'.
I couldn't find a way to do that. The closest I got are these:
struct CmdArgs {
/// Source location
#[arg(required=true)]
source: Vec<String>,
/// Destination location
#[arg(required=true)]
dest: String,
}
but this one doesn't allow to make remaining arguments as positional with --
, like
util -- a -x
doesn't work. It is supposed to accept -x
as DEST argument, but fails:
error: unexpected argument '-x' found
Usage: util [OPTIONS] <SOURCE>... <DEST>
For more information, try '--help'.
The other option would be just:
struct CmdArgs {
/// Source location
#[arg(required=true)]
source: Vec<String>,
This gives me the right behavior (with having to split the dest
argument output source
manually), but the help message will be wrong/misleading then:
Usage: util [OPTIONS] <SOURCE>...
Arguments:
<SOURCE>... Source location
And I cannot find a way to customize the help message like it should be:
Usage: util [OPTIONS] <SOURCE>... <DEST>
Arguments:
<SOURCE>... Source location
<DEST> Destination location
Can Clap really not handle such a common case? Is there another library which can?