Skip to content

Support non-Unix options (e.g. find -exec, bash +O shopt, cmd.exe /c, gcc -Wl,) #2468

@mkayaalp

Description

@mkayaalp

Child Tasks:

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Describe your use case

There are many CLIs that do not follow the Unix way of short vs. long options. While it might not be a good idea for new programs to have such an interface, it may be needed for compatibility.

Examples

1. Long option with a single hyphen-minus (-) instead of a double hyphen-minus (--)

The examples are probably too many to count, as this is very common. From the output of find --help:

      -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE

From the output of gcc --help:

  -dumpspecs               Display all of the built in spec strings.
  -dumpversion             Display the version of the compiler.
  -dumpmachine             Display the compiler's target processor.

From the output of ld --help:

  -rpath PATH                 Set runtime shared library search path
  -rpath-link PATH            Set link time shared library search path
  -shared, -Bshareable        Create a shared library
  -pie, --pic-executable      Create a position independent executable

From the output of qemu-system-x86_64 --help

-serial dev     redirect the serial port to char device 'dev'
-parallel dev   redirect the parallel port to char device 'dev'
-monitor dev    redirect the monitor to char device 'dev'

2. Long option with a single plus (+) instead of a double hyphen-minus (--)

I'm sure there are others, but I can point to the output of Xwayland --help for this:

+xinerama              Enable XINERAMA extension
-xinerama              Disable XINERAMA extension
...
+extension name        Enable extension
-extension name        Disable extension

3. Short option with a plus (+) instead of a hyphen-minus (-)

In this case it is a short option because it can be combined as +OO opt1 opt2. Although the value needs to be separated with a space: +Oopt1 does not work. From man 1 bash:

       [-+]O [shopt_option]
                 shopt_option  is  one  of  the  shell options accepted by the
                 shopt  builtin  (see  SHELL  BUILTIN  COMMANDS  below).    If
                 shopt_option is present, -O sets the value of that option; +O
                 unsets it.  If shopt_option is not supplied,  the  names  and
                 values  of the shell options accepted by shopt are printed on
                 the standard output.  If the invocation  option  is  +O,  the
                 output is displayed in a format that may be reused as input.

4. No space between option and value

As in short options, but the option is not a single character, so combining is not possible. From gcc --help:

  -Wa,<options>            Pass comma-separated <options> on to the assembler.
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor.
  -Wl,<options>            Pass comma-separated <options> on to the linker.

(I guess it looks like W is the short option and the first value a/p/l signifies assembler, preprocessor, or linker. But combining such short options would not make sense.)

5. Long option with value after equals (=), but without the double hyphen-minus (--)

From dd --help

  count=N         copy only N input blocks
  ibs=BYTES       read up to BYTES bytes at a time (default: 512)
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time (default: 512)
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list

6. Windows way: slash (/) instead of double hyphen-minus (--) and colon (:) instead of equals (=)

Not very familiar with Windows command line parameters, but from examples it seems only long options, mostly single-letter, are used. They are still "long" options since there is no combining. Option values are separated by a space or a colon (:). Also, /? is the equivalent of -h, --help.

cmd [/c|/k] [/s] [/q] [/d] [/a|/u] [/t:{<b><f> | <f>}] [/e:{on | off}] [/f:{on | off}] [/v:{on | off}] [<string>]

icacls <filename> [/grant[:r] <sid>:<perm>[...]] [/deny <sid>:<perm>[...]] [/remove[:g|:d]] <sid>[...]] [/t] [/c] [/l] [/q] [/setintegritylevel <Level>:<policy>[...]]

pathping [/n] [/h <maximumhops>] [/g <hostlist>] [/p <Period>] [/q <numqueries> [/w <timeout>] [/i <IPaddress>] [/4 <IPv4>] [/6 <IPv6>][<targetname>]

winnt32 [/checkupgradeonly] [/cmd: <CommandLine>] [/cmdcons] [/copydir:{i386|ia64}\<FolderName>] [/copysource: <FolderName>] [/debug[<Level>]:[ <FileName>]] [/dudisable] [/duprepare: <pathName>] [/dushare: <pathName>] [/emsport:{com1|com2|usebiossettings|off}] [/emsbaudrate: <BaudRate>] [/m: <FolderName>]  [/makelocalsource] [/noreboot] [/s: <Sourcepath>] [/syspart: <DriveLetter>] [/tempdrive: <DriveLetter>] [/udf: <ID>[,<UDB_File>]] [/unattend[<Num>]:[ <AnswerFile>]]

Describe the solution you'd like

Instead of (or in addition to) specifying short vs. long, maybe we could specify:

  • The prefix: "-", "--", "/", "+", ""
  • Whether to combine as in short options or not
  • Whether to allow, or require, or disallow space between the option name and its value
  • The separator between the option name and its value(s): "=", ":"

Alternatives, if applicable

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parsingArea: Parser's logic and needs it changed somehow.C-enhancementCategory: Raise on the bar on expectationsS-waiting-on-mentorStatus: Needs elaboration on the details before doing a 'Call for participation'

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions