Skip to content

Conflicting with a positional should allow users to skip it, passing in another positional instead #1794

@nayeemrmn

Description

@nayeemrmn

Issuehunt badges

Rust Version

rustc 1.42.0 (b8cedc004 2020-03-09)

Code

use clap;
use clap::Arg;
use clap::ArgGroup;

fn main() {
  let app = clap::App::new("hello")
    .bin_name("deno")
    .arg(
      Arg::with_name("option1")
        .long("option1")
        .takes_value(false),
    )
    .arg(
      Arg::with_name("pos1")
        .takes_value(true),
    )
    .group(
      ArgGroup::with_name("arg1")
        .args(&["pos1", "option1"])
        .required(true),
    )
    .arg(
      Arg::with_name("pos2")
        .takes_value(true)
    );

    match app.get_matches_from_safe(std::env::args().collect::<Vec<String>>()) {
      Ok(_) => (),
      Err(err) => err.exit(),
    }
}

Steps to reproduce the issue

cargo run -- -h

Affected Version of clap*

2.33.0

Actual Behavior Summary

USAGE:
    deno <pos1|--option1> [pos1]

cargo run -- --option1 abcd binds abcd to pos1 and complains about conflict between option1 and pos1

Blocks denoland/deno#4635, ref denoland/deno#4635 (comment).

Expected Behavior Summary

USAGE:
    deno <pos1|--option1> [pos2]

cargo run -- --option1 abcd should bind abcd to pos2. In other words, it should detect --option1 having been given as an option and accordingly skip pos1 which --option1 is grouped with.

--

If this is actually intended I welcome suggestions as to how I can get the above behaviour. But what else should be the semantics of grouping positional args with options?


IssueHunt Summary

Backers (Total: $20.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...A-parsingArea: Parser's logic and needs it changed somehow.C-bugCategory: bugS-waiting-on-decisionStatus: Waiting on a go/no-go before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions