diff --git a/main.go b/main.go index 23f6bd7..121e80e 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,12 @@ type Args struct { Help bool } +// Custom usage function to display help +func usage() { + fmt.Println("Usage: mycli [options]") + flag.PrintDefaults() +} + // ParseArgs parses the command-line arguments into a Args struct func ParseArgs() Args { var versionShortFlag bool @@ -25,11 +31,11 @@ func ParseArgs() Args { var helpShortFlag bool var helpLongFlag bool - flag.BoolVar(&versionShortFlag, "v", false, "Print version information") + flag.BoolVar(&versionShortFlag, "v", false, "") flag.BoolVar(&versionLongFlag, "version", false, "Print version information") - flag.BoolVar(&debugShortFlag, "d", false, "Enable debug mode") + flag.BoolVar(&debugShortFlag, "d", false, "") flag.BoolVar(&debugLongFlag, "debug", false, "Enable debug mode") - flag.BoolVar(&helpShortFlag, "h", false, "Show help") + flag.BoolVar(&helpShortFlag, "h", false, "") flag.BoolVar(&helpLongFlag, "help", false, "Show help") flag.Parse() @@ -46,6 +52,7 @@ func init() { func main() { args := ParseArgs() + flag.Usage = usage // Handle version flag if args.Version { @@ -55,9 +62,8 @@ func main() { // Handle help if args.Help { - fmt.Println("Usage: mycli [options]") - flag.PrintDefaults() - os.Exit(0) + flag.Usage() + return } fmt.Println("Hello, World!")