-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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