Skip to content

Commit

Permalink
feat: add custom usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-b committed May 26, 2021
1 parent 79c4ddc commit 50a6c05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions cmd/mdtoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 50a6c05

Please sign in to comment.