Command line options standard aproach for parsing?

I read a little about how programs handle command line options. But the information seems "incomplete", which I read:

  • Parameters can be preceded by a "-" or "/", if in front of them.
  • Parameters may have additional arguments (which are unsigned)
  • option arguments follow the option directly, with or without a space.
  • Parameters can be a single letter or a full word.
  • options can be combined inside one "option": -abc equals -a -b -c

(A source)

Now I’m really curious: what options do you give the ā€œ-ā€ sign and which do not. Also, merging options in 1 seems incompatible with full-word variants? "file" may be a full word, but it can also mean "-f", "-i", "-l", "-e", 4 different switches. Or even: "-f" with "ile" as option_argument.

Am I misunderstanding something?

0
source share
2 answers

On systems such as Linux, there is an agreement that parameters that are complete words use two hyphens (for example, --file ), and single-letter options use one dash (for example, -f .)

Using a slash to enter parameters comes from the old DOS and is stored in Windows.

In addition, if an option uses a whole word, it cannot be divided into several parameters. This applies to your example with -file : -file can be either one or four different options ( -f , -i , -l and -e ).

In general, how the parameters look or are processed varies greatly between programs, and there really is no specific standard.

I suggest you find some way that you like and then use it.

+2
source

There are no Windows standards for parameters / arguments / parameters, etc.

The parameters are developed in accordance with the understanding of the developers in order to facilitate their interpretation of the transmitted information.

The real reason for prefix options / or - usually used for parsing rules, since it is much easier to parse unique option prefixes with less code, rather than complex parameters with large code. Common development standards (e.g. standard use cases) minimize confusion for users;)

0
source

Source: https://habr.com/ru/post/1379130/


All Articles