mirror of
https://github.com/golang/go
synced 2024-11-26 17:07:09 -07:00
change solution to use init() method
This commit is contained in:
parent
b4630820d1
commit
cf78a8c895
@ -1196,17 +1196,16 @@ func Parsed() bool {
|
||||
// CommandLine is the default set of command-line flags, parsed from [os.Args].
|
||||
// The top-level functions such as [BoolVar], [Arg], and so on are wrappers for the
|
||||
// methods of CommandLine.
|
||||
var CommandLine = safeCommandLineFlagSet()
|
||||
|
||||
// Handle the scenario where a process run via execl() can have an empty os.Args
|
||||
func safeCommandLineFlagSet() {
|
||||
if len(os.Args) == 0 {
|
||||
return NewFlagSet("", ExitOnError)
|
||||
}
|
||||
return NewFlagSet(os.Args[0], ExitOnError)
|
||||
}
|
||||
var CommandLine *FlagSet
|
||||
|
||||
func init() {
|
||||
// Handle the scenario where a process run via execl() can have an empty os.Args
|
||||
if len(os.Args) == 0 {
|
||||
CommandLine = NewFlagSet("", ExitOnError)
|
||||
} else {
|
||||
CommandLine = NewFlagSet(os.Args[0], ExitOnError)
|
||||
}
|
||||
|
||||
// Override generic FlagSet default Usage with call to global Usage.
|
||||
// Note: This is not CommandLine.Usage = Usage,
|
||||
// because we want any eventual call to use any updated value of Usage,
|
||||
|
Loading…
Reference in New Issue
Block a user