Skip to content

Commit

Permalink
feat: add version cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
kperreau committed May 6, 2024
1 parent 0b0aafb commit 405047f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .semver.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
alpha: 0
beta: 0
rc: 0
release: v1.0.0
release: v1.0.1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Available Commands:
discover List discovered projects
help Help about any command
list List projects
version Get goac version

Flags:
-h, --help help for goac
Expand Down
56 changes: 56 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"errors"
"fmt"
"gopkg.in/yaml.v3"
"os"

"github.com/spf13/cobra"
)

// versionCmd represents the project command
var versionCmd = &cobra.Command{
Use: "version",
Example: "goac version",
Short: "Get goac version",
Long: `Use it to know your goac version.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return errors.New("bad args number")
}

return run()
},
}

type Semver struct {
Alpha int `yaml:"alpha"`
Beta int `yaml:"beta"`
RC int `yaml:"rc"`
Release string `yaml:"release"`
}

func run() error {
// read file .semver.yaml
data, err := os.ReadFile(".semver.yaml")
if err != nil {
return fmt.Errorf("error: %v", err)
}

// unmarshall YAML
var semver Semver
err = yaml.Unmarshal(data, &semver)
if err != nil {
return fmt.Errorf("error: %v", err)
}

// Print 'release'
fmt.Printf("goac version %s\n", semver.Release)

return nil
}

func init() {
rootCmd.AddCommand(versionCmd)
}

0 comments on commit 405047f

Please sign in to comment.