|
| 1 | +// Copyright © 2018 mritd <[email protected]> |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in |
| 11 | +// all copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | +// THE SOFTWARE. |
| 20 | + |
| 21 | +package cmd |
| 22 | + |
| 23 | +import ( |
| 24 | + "encoding/base64" |
| 25 | + "fmt" |
| 26 | + "runtime" |
| 27 | + |
| 28 | + "github.com/spf13/cobra" |
| 29 | +) |
| 30 | + |
| 31 | +var bannerBase64 = "CiAgLm9vb29vby4gICAgIG84byAgICAgIC4gICAgICBvb29vb29vb29vb28gb29vbwogZDhQJyAgYFk4YiAgICBgIicgICAgLm84ICAgICAgYDg4OCcgICAgIGA4IGA4ODgKODg4ICAgICAgICAgICBvb29vICAubzg4OG9vICAgICA4ODggICAgICAgICAgODg4ICAgLm9vb29vLiAgb29vbyBvb29vICAgIG9vbwo4ODggICAgICAgICAgIGA4ODggICAgODg4ICAgICAgIDg4OG9vb284ICAgICA4ODggIGQ4OCcgYDg4YiAgYDg4LiBgODguICAuOCcKODg4ICAgICBvb29vbyAgODg4ICAgIDg4OCAgICAgICA4ODggICAgIiAgICAgODg4ICA4ODggICA4ODggICBgODguLl04OC4uOCcKYDg4LiAgICAuODgnICAgODg4ICAgIDg4OCAuICAgICA4ODggICAgICAgICAgODg4ICA4ODggICA4ODggICAgYDg4OCdgODg4JwogYFk4Ym9vZDhQJyAgIG84ODhvICAgIjg4OCIgICAgbzg4OG8gICAgICAgIG84ODhvIGBZOGJvZDhQJyAgICAgYDgnICBgOCc=" |
| 32 | + |
| 33 | +var versionTpl = `%s |
| 34 | +
|
| 35 | +Name: gitflow-toolkit |
| 36 | +Version: %s |
| 37 | +Arch: %s |
| 38 | +BuildTime: %s |
| 39 | +CommitID: %s |
| 40 | +` |
| 41 | + |
| 42 | +var ( |
| 43 | + Version string |
| 44 | + BuildTime string |
| 45 | + CommitID string |
| 46 | +) |
| 47 | + |
| 48 | +var versionCmd = &cobra.Command{ |
| 49 | + Use: "version", |
| 50 | + Short: "Print version", |
| 51 | + Long: ` |
| 52 | +Print version.`, |
| 53 | + Run: func(cmd *cobra.Command, args []string) { |
| 54 | + banner, _ := base64.StdEncoding.DecodeString(bannerBase64) |
| 55 | + fmt.Printf(versionTpl, banner, Version, runtime.GOOS+"/"+runtime.GOARCH, BuildTime, CommitID) |
| 56 | + }, |
| 57 | +} |
| 58 | + |
| 59 | +func init() { |
| 60 | + RootCmd.AddCommand(versionCmd) |
| 61 | +} |
0 commit comments