From 50a6c0589d602bddf1935ad6c2d95c29d5142508 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 25 May 2021 23:50:02 -0400 Subject: [PATCH] feat: add custom usage --- README.md | 8 +++++--- cmd/mdtoc/main.go | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e934279..538e7f3 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,13 @@ go get github.com/jar-b/mdtoc/cmd/mdtoc ``` $ mdtoc -h -Usage of mdtoc: +Usage: mdtoc [flags] [filename] + +Flags: -dry-run - print generated contents, but do not write to file (optional) + print generated contents, but do not write to file (optional) -force - force overwrite of existing contents (optional) + force overwrite of existing contents (optional) ``` Examples: diff --git a/cmd/mdtoc/main.go b/cmd/mdtoc/main.go index a2dc2b6..5bc7ff3 100644 --- a/cmd/mdtoc/main.go +++ b/cmd/mdtoc/main.go @@ -13,6 +13,14 @@ var ( force, dryRun bool ) +func init() { + // slightly better usage output + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [filename]\n\nFlags:\n", os.Args[0]) + flag.PrintDefaults() + } +} + func main() { flag.BoolVar(&force, "force", false, "force overwrite of existing contents (optional)") flag.BoolVar(&dryRun, "dry-run", false, "print generated contents, but do not write to file (optional)")