Skip to content

Commit

Permalink
Merge pull request #99 from runpod/96-api-key-is-required-for-version…
Browse files Browse the repository at this point in the history
…-cmd

fix: support --version flag
  • Loading branch information
DireLines authored Feb 13, 2024
2 parents 7a2ad12 + 4e7ae63 commit 674af43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ func registerCommands() {
// file transfer via croc
rootCmd.AddCommand(croc.ReceiveCmd)
rootCmd.AddCommand(croc.SendCmd)

// Version
rootCmd.Version = version
rootCmd.Flags().BoolP("version", "v", false, "Print the version of runpodctl")
rootCmd.SetVersionTemplate(`{{printf "runpodctl %s\n" .Version}}`)
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(ver string) {
version = ver
api.Version = ver
rootCmd.Version = ver

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
Expand Down
7 changes: 4 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "runpodctl version",
Long: "runpodctl version",
Use: "version",
Short: "runpodctl version",
Long: "runpodctl version",
Hidden: true,
Run: func(c *cobra.Command, args []string) {
fmt.Println("runpodctl " + version)
},
Expand Down

0 comments on commit 674af43

Please sign in to comment.