jpictl: add --version and version command #44

Merged
karasz merged 1 commits from pr-amery-version into main 8 months ago
  1. 1
      .gitignore
  2. 7
      cmd/jpictl/main.go
  3. 31
      cmd/jpictl/version.go

1
.gitignore vendored

@ -1 +1,2 @@
.tmp
.version

7
cmd/jpictl/main.go

@ -2,6 +2,8 @@
package main
import (
_ "embed"
"github.com/spf13/cobra"
)
@ -12,8 +14,9 @@ const (
var (
rootCmd = &cobra.Command{
Use: CmdName,
Short: "control tool for jpi.cloud",
Use: CmdName,
Short: "control tool for jpi.cloud",
Version: version,
}
)

31
cmd/jpictl/version.go

@ -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…
Cancel
Save