aboutsummaryrefslogtreecommitdiffsponsor
path: root/cmd/removepkg/main.go
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2022-05-20 15:59:02 -0500
committerSlack Coder <slackcoder@server.ky>2022-05-20 15:59:02 -0500
commitd0f06ff4ef35fd54910c686cb2727a08b3fb89cd (patch)
tree027c85d7526876211740be6c8f494855d9f5c607 /cmd/removepkg/main.go
parenta1e7249e712bfc7bbcf6275bdd87f2343d60f81a (diff)
downloadpkgtools-go-d0f06ff4ef35fd54910c686cb2727a08b3fb89cd.tar.xz
add help flag to commands
Display command usage using the '--help' flag.
Diffstat (limited to 'cmd/removepkg/main.go')
-rw-r--r--cmd/removepkg/main.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/cmd/removepkg/main.go b/cmd/removepkg/main.go
index 5970112..dd21f54 100644
--- a/cmd/removepkg/main.go
+++ b/cmd/removepkg/main.go
@@ -1,24 +1,37 @@
package main
+// TODO: print help when no arguments given
+
import (
"flag"
"fmt"
"os"
"git.server.ky/slackcoder/pkgtools"
+ "github.com/pborman/getopt/v2"
)
+func usage() {
+ getopt.PrintUsage(os.Stdout)
+}
+
func ParseFlags() *pkgtools.RemovePkgFlags {
flags := pkgtools.DefaultRemovePkgFlags
flags.SetEnvValues()
- flag.Parse()
-
+ getopt.Parse()
return &flags
}
func main() {
+ getopt.SetParameters("packagename ...")
+ help := getopt.BoolLong("help", 0, "display help")
+
flags := ParseFlags()
+ if len(getopt.Args()) == 0 || *help {
+ usage()
+ return
+ }
err := pkgtools.RemovePkg(flags, flag.Args()...)
if err != nil {