Skip to content

[Feature Request]: Support flag combining for config vars and ArgumentParser flags #28253

@DanilaFe

Description

@DanilaFe

In many UNIX applications, boolean flags can be passed shorthand, turning --bla into -b. Also, adjacent boolean flags passed as -f -g can be written next to each other as -fg. Today, config vars don't support shorthand options, and neither config vars nor ArgumentParser support writing flags next to each other. I tried the following program:

use ArgumentParser;

config var x: bool;
config var y: bool;

proc main(args: [] string) throws {
  var parser = new argumentParser();
  var flagArg1 = parser.addFlag(name="debugFlag", ["-d"], defaultValue=false);
  var flagArg2 = parser.addFlag(name="debugFlag2", ["-e"], defaultValue=false);
  parser.parseArgs(args);

  writeln("x ", x);
  writeln("y ", y);
  writeln("debugFlag ", flagArg1.valueAsBool());
  writeln("debugFlag2 ", flagArg2.valueAsBool());
}

Here, -x alone doesn't work, and nor does -xy, nor -de (though -d -e does work).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions