-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(version): add version command to show utility version info
- Loading branch information
1 parent
4c91607
commit e5fb522
Showing
6 changed files
with
131 additions
and
3 deletions.
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,3 +1,11 @@ | ||
.idea/ | ||
bin/ | ||
dist/ | ||
node_modules/ | ||
package-lock.json | ||
argus-configuration.yaml | ||
collectorset-controller-configuration.yaml | ||
argus.yaml.bkp | ||
collectorset-controller.yaml.bkp | ||
lmc-configuration.yaml | ||
lmc-configuration.json |
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,84 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/spf13/cobra" | ||
"time" | ||
) | ||
|
||
var ( | ||
Version = "dev" | ||
Commit = "none" | ||
Date = "unknown" | ||
BuiltBy = "unknown" | ||
) | ||
|
||
type versionMap struct { | ||
Version string | ||
Commit string | ||
BuildDateUTC time.Time | ||
BuildDate time.Time | ||
BuiltBy string | ||
} | ||
|
||
// versionCmd represents the version command | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
ValidArgsFunction: cobra.NoFileCompletions, | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if Short { | ||
cmd.Printf("%s\n", Version) | ||
return | ||
} | ||
vm := NewVersionMap() | ||
marshal, err := json.Marshal(vm) // nolint: errcheck | ||
if err != nil { | ||
cmd.Printf("failing to print version info: %s\n", err) | ||
return | ||
} | ||
cmd.Println(string(marshal)) | ||
}, | ||
} | ||
|
||
func NewVersionMap() *versionMap { | ||
vm := &versionMap{ | ||
Version: Version, | ||
Commit: Commit, | ||
BuiltBy: BuiltBy, | ||
} | ||
date, err := time.Parse(time.RFC3339, Date) | ||
if err != nil { | ||
return nil | ||
} | ||
vm.BuildDateUTC = date.UTC() | ||
vm.BuildDate = date.Local() | ||
return vm | ||
} | ||
|
||
var Short bool | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// versionCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
versionCmd.Flags().BoolVar(&Short, "short", false, "Show short Version") | ||
} |
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 |
---|---|---|
|
@@ -21,4 +21,7 @@ commands: | |
- name: bash | ||
- name: zsh | ||
- name: powershell | ||
- name: fish | ||
- name: fish | ||
- name: version | ||
flags: | ||
- short |
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,20 @@ | ||
{ | ||
"dependencies": { | ||
"@commitlint/cli": "^12.1.4", | ||
"@commitlint/config-conventional": "^12.1.4", | ||
"husky": "^7.0.4" | ||
}, | ||
"devDependencies": { | ||
"commitizen": "^4.2.4", | ||
"cz-conventional-changelog": "^3.0.1" | ||
}, | ||
"scripts": { | ||
"prepare": "husky install", | ||
"postinstall": "husky install" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
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