I want to create an external function for usage display in Golang, but I don't know how to call the flag variable. This is my actual code:
package main
import (
"flag"
"fmt"
"os"
)
func Usage() {
if ArgSend {
fmt.Printf("Usage: SEND")
flag.PrintDefaults()
os.Exit(0)
} else if ArgTest {
fmt.Printf("Usage: -test")
flag.PrintDefaults()
os.Exit(0)
} else if ArgMacro {
fmt.Printf("Usage: -macro")
os.Exit(0)
} else {
fmt.Printf("Usage of: <-test|-send|-macro>
")
os.Exit(0)
}
}
func main() {
//defaults variables
ArgTest, ArgSend, ArgMacro := false, false, false
// Args parse
flag.BoolVar(&ArgTest, "-test", false, "run test mode")
flag.BoolVar(&ArgSend, "-send", false, "run send mode")
flag.BoolVar(&ArgMacro, "-macro", false, "run macro mode")
flag.Parse()
Usage()
}
Return this error:
F:\dev\GoLang\gitlab\EasySend\tmp>go run stackoverflow.go -test
# command-line-arguments
.\stackoverflow.go:10:5: undefined: ArgSend
.\stackoverflow.go:15:12: undefined: ArgTest
.\stackoverflow.go:20:12: undefined: ArgMacro
How can I check flag parse if ArgSend is true/false?