diff --git a/.semver.yaml b/.semver.yaml index 36a2acc..1443f27 100644 --- a/.semver.yaml +++ b/.semver.yaml @@ -1,4 +1,4 @@ alpha: 0 beta: 0 rc: 0 -release: v1.0.0 +release: v1.0.1 diff --git a/README.md b/README.md index 390c5a3..008ff45 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..65f5a22 --- /dev/null +++ b/cmd/version.go @@ -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) +}