Skip to content

Instantly share code, notes, and snippets.

@17twenty 17twenty/demo.go
Created Sep 19, 2017

Embed
What would you like to do?
Simple demo of setting up the usage preamble
package main
import (
"flag"
"fmt"
"os"
"path"
)
var (
// VERSION is a link time version number specify it with
// `go build -ldflags="-X main.VERSION=0.1"`
VERSION string
configFile = flag.String("c", "config.json", "Use a config file")
)
func main() {
flag.Usage = func() {
fmt.Println(path.Base(os.Args[0]), "- version", VERSION)
fmt.Println("usage:")
flag.PrintDefaults()
}
flag.Parse()
fmt.Println("Hello world")
}
@17twenty

This comment has been minimized.

Copy link
Owner Author

17twenty commented Sep 19, 2017

Running it....

$ flaggot -h
flaggot - version
usage:
  -c string
        Use a config file (default "config.json")
exit status 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.