add version command
This commit is contained in:
@@ -233,6 +233,21 @@ func ServeRequested() (requested bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VersionRequested checks if the first command line argument is "version" and returns
|
||||||
|
// whether the version should be printed and the program should exit.
|
||||||
|
//
|
||||||
|
// Return Values
|
||||||
|
// - requested: true if the 'version' subcommand was provided, false otherwise.
|
||||||
|
func VersionRequested() (requested bool) {
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
switch strings.ToLower(os.Args[1]) {
|
||||||
|
case "version", "-v", "--v", "-version", "--version":
|
||||||
|
requested = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// KV is a key/value pair.
|
// KV is a key/value pair.
|
||||||
type KV struct{ Key, Value string }
|
type KV struct{ Key, Value string }
|
||||||
|
|
||||||
@@ -364,7 +379,7 @@ func PrintHelp(cfg *C, printer io.Writer) {
|
|||||||
)
|
)
|
||||||
_, _ = fmt.Fprintf(
|
_, _ = fmt.Fprintf(
|
||||||
printer,
|
printer,
|
||||||
`Usage: %s [env|help|identity|serve]
|
`Usage: %s [env|help|identity|serve|version]
|
||||||
|
|
||||||
- env: print environment variables configuring %s
|
- env: print environment variables configuring %s
|
||||||
- help: print this help text
|
- help: print this help text
|
||||||
@@ -372,6 +387,7 @@ func PrintHelp(cfg *C, printer io.Writer) {
|
|||||||
- serve: start ephemeral relay with RAM-based storage at /dev/shm/orlyserve
|
- serve: start ephemeral relay with RAM-based storage at /dev/shm/orlyserve
|
||||||
listening on 0.0.0.0:10547 with 'none' ACL mode (open relay)
|
listening on 0.0.0.0:10547 with 'none' ACL mode (open relay)
|
||||||
useful for testing and benchmarking
|
useful for testing and benchmarking
|
||||||
|
- version: print version and exit (also: -v, --v, -version, --version)
|
||||||
|
|
||||||
`,
|
`,
|
||||||
cfg.AppName, cfg.AppName,
|
cfg.AppName, cfg.AppName,
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -31,6 +31,13 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
runtime.GOMAXPROCS(128)
|
runtime.GOMAXPROCS(128)
|
||||||
debug.SetGCPercent(10)
|
debug.SetGCPercent(10)
|
||||||
|
|
||||||
|
// Handle 'version' subcommand early, before any other initialization
|
||||||
|
if config.VersionRequested() {
|
||||||
|
fmt.Println(version.V)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var cfg *config.C
|
var cfg *config.C
|
||||||
if cfg, err = config.New(); chk.T(err) {
|
if cfg, err = config.New(); chk.T(err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user