import "flag"

flag The package implements the parsing of command line parameters .

requirement :

use flag.String(), Bool(), Int() Equal function registration flag, The following example declares an integer flag, The parsing results are saved in *int Pointer ip in :
import "flag" var ip = flag.Int("flagname", 1234, "help message for flagname")
If you like it , You can also flag Bind to a variable , use Var Series function :
var flagvar int func init() { flag.IntVar(&flagvar, "flagname", 1234, "help
message for flagname") }
Or you can customize one for flag Type of ( satisfy Value Interface ) And use this type for flag analysis , as follows :
flag.Var(&flagVal, "name", "help message for flagname")
Right flag, The default value is the initial value of the variable .

At all flag After registration , call :
To parse command-line parameters and write registered flag in .

After parsing ,flag Can be used directly . If you use flag oneself , They are pointers ; If you bind to a variable , They are values .
fmt.Println("ip has value ", *ip) fmt.Println("flagvar has value ", flagvar)
After analysis ,flag The following parameters can be downloaded from flag.Args() To obtain or use in flag.Arg(i) Separate access . These parameters are indexed from 0 reach flag.NArg()-1.

command line flag grammar :
-flag -flag=x -flag x // Only non bool Type flag sure
have access to 1 Or 2 individual '-' Number , The effect is the same . The last format cannot be used for bool Type flag, Because if there is a file named 0,false Isochronous , The order is as follows :
cmd -x *
Its meaning will change . You have to use it -flag=false Format to close a bool type flag.

Flag Parsing in the first non flag parameter ( single "-" no flag parameter ) Stop before , Or in the terminator "--" Then stop .

integer flag accept 1234,0664,0x1234 Etc , It can also be negative .bool type flag It can be :
1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False
time slot flag Accept any legal offer time.ParseDuration Input for .

Default command line flag Function control of set and package level .FlagSet Types allow programmers to define independent flag collection , For example, the implementation of the command line interface under the sub command .FlagSet The method is very similar to the package level function .

©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing