Basic Concepts
Argument
Data passed sequentially in the program command line without name identifiers is called an Argument. The input of arguments is sequential.
Option
Additional input that controls the program logic and has a name identifier is called Options. Option names are prefixed with - or --. Options are unordered and can be placed in any position in the command line. Options may or may not have associated data. In other similar third-party functional components, options work similarly to Flags.
Additionally, following the traditional command line management practice, options can have shorthand aliases to simplify command line argument input. Shorthand aliases are often set as a single letter.
Option Positioning and = Sign
The gcmd component supports options being placed anywhere in the command line, meaning the following command line option inputs are essentially the same:
gf build main.go -a amd64 -o linux -n app -yes
gf -a amd64 -o linux build main.go -yes -n app
gf -yes -n app build -o linux -a amd64 main.go
In these examples,
gf/build/main.goare arguments with indices0,1,2respectively; since arguments are ordered, changing the order in the command line does not change the order of these three.a/o/nare options with data. Since the order is irrelevant, data is retrieved by option name, hence they can be placed freely.yesis an option without data and can also be placed freely.
Options and their data can be connected with a space or an = sign, like:
gf build main.go -a=amd64 -o=linux -n=app -yes
Default Parsing Rules
The gcmd module provides several package methods to obtain default command line parsing rules. By default, it will automatically recognize arguments and options.
Situations with the = Sign in the Command Line
gf build main.go -a=amd64 -o=linux -n=app -yes
By default,
gf/build/main.goare arguments, with indices0,1,2.a/o/n/yeswill be parsed as options, withyesbeing an option without data.
Not Using = Sign to Connect Option Parameters
gf build main.go -a amd64 -o linux -n app -yes
By default,
gf/build/main.goare arguments, with indices0,1,2.a/o/n/yeswill be parsed as options, withyesbeing an option without data.