3

I'm using clap to parse arguments. I want to use the single dash (-) and more than one character in the argument, like -Fmin 1. Adding long("Fmin") gives me that but with two dashes (--).

I'm aware that using a single dash and single character together is the norm. But is it possible to have clap use more than a single character when using the short() form? Or override the long-form so it defaults to a single dash?

let matches = App::new("clap")
    .arg(Arg::with_name("Fmin")
        .required(false)
        .takes_value(true)
        .short("Fmin")
        .multiple(false)
        .possible_values(&["min"])
    )
    .get_matches();
kometen
  • 6,536
  • 6
  • 41
  • 51
  • Ugh… But why though? Principle of least astonishment: most modern tools use `-` for short options and `-Fmin` is the same as `-F -m -i -n`, and `--` for long options. Don't do this to your users. – mcarton Jan 18 '21 at 10:38
  • You are correct. Clap can reduce options with possible_values(), so this can reduce ambiguity. – kometen Jan 18 '21 at 11:15
  • 1
    @mcarton might be a requirement to replace an existing tool, single-dash long options are common in some contexts e.g. Sun/Oracle or Apple-provided CLI tools. – Masklinn Jan 18 '21 at 13:56

1 Answers1

2

is it possible to have clap use more than a single character when using the short() form? Or override the long-form so it defaults to a single dash?

Judging by this issue, single-hyphen long options are not yet supported by clap.

user4815162342
  • 141,790
  • 18
  • 296
  • 355