-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |