Skip to content

std.getopt does not support order-sensitive options #10902

@CyberShadow

Description

@CyberShadow

Consider the following hypothetical program invocations:

$ program --include=dir1 --exclude=*.avi
$ program file1 -C dir2 file2 -C dir3 file3

Both examples are not currently supported by std.getopt:

  • In the first example, we lose the information of whether --include=dir1 was specified before --exclude=*.avi. As such, we would not be able to know if the user wants the program to act on .avi files in dir1.
  • In the second example, we lose the relative ordering of positional arguments and options, so we don't know which directory each file should be searched for.

The above examples are based on the CLI of real ubiquitous tools - see find(1), rsync(1), tar(1).

The first example is not supported because std.getopt acts on options in the order they are declared in the program, not the order they apprear on the command line. Thus, getopt(args, "include", ..., "exclude", ...) will process all --include arguments before any --exclude arguments.
The second example is not supported because std.getopt does not allow capturing the relative order of positional arguments with respect to options; the two are separated, losing ordering, with one being returned in the mutated args and the other in the passed ref-variable or predicate.

We need:

  1. an option to switch the processing order of arguments to be in the order they were specified on the command line
  2. a method of receiving positional arguments in-band with options (e.g. via a predicate).

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