Skip to content

Surprising behaviour: argfile reads @argfiles after -- #46

Closed as not planned
@passcod

Description

@passcod

Found in watchexec/watchexec#717.

When there's a trailing_var_arg (or in general, really), I would expect that argfile would not parse beyond the -- separator. That is, these should load an argfile:

command @argfile --option
command --option @argfile
command @argfile -- sub args

But this should not:

command --option -- @bazel-target-or-something

Here's a minimal repro:

#!/usr/bin/env cargo

//! ```cargo
//! [dependencies]
//! argfile = "0.1.6"
//! clap = { version = "4.4.11", features = ["derive"] }
//! ```

use clap::{Parser, ValueHint};

#[derive(Debug, Clone, Parser)]
pub struct Args {
	#[arg(
		trailing_var_arg = true,
		num_args = 1..,
		value_hint = ValueHint::CommandString,
		value_name = "COMMAND",
	)]
	pub command: Vec<String>,
}

fn main() {
    let args = argfile::expand_args(argfile::parse_fromfile, argfile::PREFIX)
		.expect("while reading @argfile");
    let args = Args::parse_from(args);
    dbg!(args);
}

Calling with ./repro.rs -- @not-an-argfile panics, while I would expect it to silently ignore and leave the @not-an-argfile in the args.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions