From a336e461662428e8f474856f989b033c573a1451 Mon Sep 17 00:00:00 2001 From: Andrei Burdulescu Date: Tue, 12 Dec 2023 12:00:58 +0200 Subject: [PATCH] add cli pkg --- internal/cli/cmd/cmd.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internal/cli/cmd/cmd.go diff --git a/internal/cli/cmd/cmd.go b/internal/cli/cmd/cmd.go new file mode 100644 index 0000000..245db6f --- /dev/null +++ b/internal/cli/cmd/cmd.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "flag" + "fmt" + "os" +) + +type Cmd struct { + // command name + Name string + + // short usage message to be used in the app + Short string + + // long usage message + Long string + + // flag set + Flags *flag.FlagSet +} + +func (c *Cmd) Init() { + if c.Name == "" { + panic("cmd: missing Name") + } + c.Flags = flag.NewFlagSet(c.Name, flag.ContinueOnError) + c.Flags.Usage = func() { + fmt.Fprint(os.Stderr, c.Long) + c.Flags.PrintDefaults() + } +}