Skip to content

Instantly share code, notes, and snippets.

@marpaia
Created November 12, 2017 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marpaia/8adc4cf0a08d84824e9d8792567db1cc to your computer and use it in GitHub Desktop.
Save marpaia/8adc4cf0a08d84824e9d8792567db1cc to your computer and use it in GitHub Desktop.
A simple template main Go file for use that uses kolide/kit's version package.
package main
import (
"fmt"
"os"
"strings"
"github.com/kolide/kit/version"
)
func runVersion(args []string) error {
version.PrintFull()
return nil
}
func usage() {
fmt.Fprintf(os.Stderr, "USAGE\n")
fmt.Fprintf(os.Stderr, " %s <mode> --help\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "MODES\n")
fmt.Fprintf(os.Stderr, " version Print full version information\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "VERSION\n")
fmt.Fprintf(os.Stderr, " %s\n", version.Version().Version)
fmt.Fprintf(os.Stderr, "\n")
}
func main() {
if len(os.Args) < 2 {
usage()
os.Exit(1)
}
var run func([]string) error
switch strings.ToLower(os.Args[1]) {
case "version":
run = runVersion
default:
usage()
os.Exit(1)
}
if err := run(os.Args[2:]); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment