ko1nksm / getoptions

An elegant option/argument parser for shell scripts (full support for bash and all POSIX shells)
Creative Commons Zero v1.0 Universal
414 stars 21 forks source link

Difference between param and option #35

Closed shinokada closed 3 years ago

shinokada commented 3 years ago

What is the difference between param and option?

param - Define an option that takes an argument
option - Define an option that takes an optional argument

I can see that option has on and no:

on:STRING - The positive value
no:STRING - The negative value

It seems like a mixture of flag and option. The option can be used as a flag and also you can add an argument.

Is this a correct interpretation?

ko1nksm commented 3 years ago

param

It requires a value. For example, --foobar VALUE is correct, but --foobar is wrong.

option

It accepts a value, but can be omitted. For example, --foobar=VALUE and --foobar are correct. If you omit the value, the default value is the value specified by on.

An option is a param whose value can be omitted, and an option without a value can be regarded as a kind of flag.

shinokada commented 3 years ago

The option has init and on. If the default value is the value specified by on, then what is the init for?

init:[@INIT-VALUE | =STRING | CODE] - Initial value
...
on:STRING - The positive value
no:STRING - The negative value
ko1nksm commented 3 years ago

The init is the value when no options are specified. That is, the value when none of -?, +?, --*, --no-* are specified. The "default value" is the default value when the option is specified (but without a value).

The term "default value" is ambiguous, so we use init (initial value when no option is specified) and on (the value when a command line option without a value is specified) instead.