pkg.tk-software.de/gotice@v0.4.1-0.20240224130243-6adec687b106/version.go (about) 1 // Copyright 2023-2024 Tobias Koch. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "flag" 9 "fmt" 10 "runtime" 11 12 "pkg.tk-software.de/gotice/version" 13 ) 14 15 // VersionCommand implements the subcommand `version`. 16 type VersionCommand struct { 17 fs *flag.FlagSet 18 } 19 20 // NewVersionCommand creates and returns the subcommand `generate`. 21 func NewVersionCommand() *VersionCommand { 22 cmd := &VersionCommand{ 23 fs: flag.NewFlagSet("version", flag.ContinueOnError), 24 } 25 26 return cmd 27 } 28 29 // Name returns the name of the subcommand. 30 func (v *VersionCommand) Name() string { 31 return v.fs.Name() 32 } 33 34 // Description returns the description of the subcommand. 35 func (v *VersionCommand) Description() string { 36 return "Displays the application version" 37 } 38 39 // Init initializes the subcommand with the given command line arguments. 40 func (v *VersionCommand) Init(args []string) error { 41 return v.fs.Parse(args) 42 } 43 44 // Usage prints a usage message documenting the subcommand. 45 func (v *VersionCommand) Usage() { 46 fmt.Println("Usage: gotice version") 47 fmt.Println(v.Description()) 48 fmt.Println() 49 } 50 51 // Run executes the subcommand. 52 func (v *VersionCommand) Run() error { 53 var ver string 54 if version.Build != "" { 55 ver = version.Long() 56 } else { 57 ver = version.Short() 58 } 59 60 fmt.Printf("gotice version %s (%s/%s)\n", ver, runtime.GOOS, runtime.GOARCH) 61 fmt.Println() 62 63 return nil 64 }