Skip to content

Commit

Permalink
Merge pull request #305 from carapace-sh/version
Browse files Browse the repository at this point in the history
added version
  • Loading branch information
rsteube authored Oct 24, 2024
2 parents 7f188d3 + b3175d4 commit fac7237
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/carapace-spec/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var rootCmd = &cobra.Command{
switch args[0] {
case "-h", "--help":
cmd.Help()
case "-v", "--version":
cmd.Println(cmd.Version)
case "--codegen":
if len(args) < 2 {
return errors.New("flag needs an argument: --codegen")
Expand Down Expand Up @@ -88,7 +90,8 @@ func loadSpec(path string) (*spec.Command, error) {
return &specCmd, nil
}

func Execute() error {
func Execute(version string) error {
rootCmd.Version = version
return rootCmd.Execute()
}
func init() {
Expand Down
15 changes: 13 additions & 2 deletions cmd/carapace-spec/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package main

import "github.com/carapace-sh/carapace-spec/cmd/carapace-spec/cmd"
import (
"fmt"
"strings"

"github.com/carapace-sh/carapace-spec/cmd/carapace-spec/cmd"
)

var date string
var version = "develop"

func main() {
cmd.Execute()
if strings.HasSuffix(version, "-next") {
version += fmt.Sprintf(" (%v)", date)
}
cmd.Execute(version)
}

0 comments on commit fac7237

Please sign in to comment.