-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version command to print version (#60)
- Loading branch information
1 parent
801f6ba
commit 2b9c395
Showing
4 changed files
with
83 additions
and
4 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
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,6 +1,6 @@ | ||
package cmd | ||
|
||
func init() { | ||
RootCmd.AddCommand(upCmd) | ||
RootCmd.AddCommand(upCmd, versionCmd) | ||
initDepCmd() | ||
} |
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,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/stormcat24/protodep/version" | ||
) | ||
|
||
const art = ` | ||
________ ________ ________ _________ ________ ________ _______ ________ | ||
|\ __ \|\ __ \|\ __ \|\___ ___\\ __ \|\ ___ \|\ ___ \ |\ __ \ | ||
\ \ \|\ \ \ \|\ \ \ \|\ \|___ \ \_\ \ \|\ \ \ \_|\ \ \ __/|\ \ \|\ \ | ||
\ \ ____\ \ _ _\ \ \\\ \ \ \ \ \ \ \\\ \ \ \ \\ \ \ \_|/_\ \ ____\ | ||
\ \ \___|\ \ \\ \\ \ \\\ \ \ \ \ \ \ \\\ \ \ \_\\ \ \ \_|\ \ \ \___| | ||
\ \__\ \ \__\\ _\\ \_______\ \ \__\ \ \_______\ \_______\ \_______\ \__\ | ||
\|__| \|__|\|__|\|_______| \|__| \|_______|\|_______|\|_______|\|__|` | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Show protodep version", | ||
RunE: func(cdm *cobra.Command, args []string) error { | ||
fmt.Println(art) | ||
fmt.Println("") | ||
fmt.Println(version.Get()) | ||
return nil | ||
}, | ||
} |
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,36 @@ | ||
package version | ||
|
||
import "fmt" | ||
|
||
var ( | ||
gitCommit = "unspecified" | ||
gitCommitFull = "unspecified" | ||
buildDate = "unspecified" | ||
version = "unspecified" | ||
) | ||
|
||
type Info struct { | ||
GitCommit string | ||
GitCommitFull string | ||
BuildDate string | ||
Version string | ||
} | ||
|
||
func Get() Info { | ||
return Info{ | ||
GitCommit: gitCommit, | ||
GitCommitFull: gitCommitFull, | ||
BuildDate: buildDate, | ||
Version: version, | ||
} | ||
} | ||
|
||
func (i Info) String() string { | ||
return fmt.Sprintf( | ||
`{"Version": "%s", "GitCommit": "%s", "GitCommitFull": "%s", "BuildDate": "%s"}`, | ||
i.Version, | ||
i.GitCommit, | ||
i.GitCommitFull, | ||
i.BuildDate, | ||
) | ||
} |