Browse Source
from `git describe` using go:generate and embed Signed-off-by: Alejandro Mery <amery@jpi.io>pull/44/head
Alejandro Mery
10 months ago
3 changed files with 37 additions and 2 deletions
@ -0,0 +1,31 @@
|
||||
package main |
||||
|
||||
import ( |
||||
_ "embed" |
||||
|
||||
"fmt" |
||||
"os" |
||||
|
||||
"github.com/spf13/cobra" |
||||
) |
||||
|
||||
//go:generate sh -c "git describe | tr -d '\r\n' > .version"
|
||||
//go:embed .version
|
||||
var version string |
||||
|
||||
var versionCmd = &cobra.Command{ |
||||
Use: "version", |
||||
Short: "Returns jpictl's version", |
||||
Args: cobra.NoArgs, |
||||
Run: func(_ *cobra.Command, _ []string) { |
||||
_, _ = fmt.Fprintf(os.Stdout, "%s\n", version) |
||||
}, |
||||
} |
||||
|
||||
func init() { |
||||
if version == "" { |
||||
version = "undetermined" |
||||
} |
||||
|
||||
rootCmd.AddCommand(versionCmd) |
||||
} |
Loading…
Reference in new issue