Skip to content

Commit

Permalink
Alteration for version passing
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Dec 31, 2019
1 parent 300d8b0 commit 1784545
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 49 deletions.
47 changes: 45 additions & 2 deletions cmd/root.go
@@ -1,6 +1,9 @@
package cmd

import (
"fmt"

"github.com/morikuni/aec"
"github.com/spf13/cobra"
)

Expand All @@ -20,9 +23,12 @@ var (
Version string
)

func Execute(gitCommit, version string) error {
GitCommit = gitCommit
// Execute faasd
func Execute(version, gitCommit string) error {

// Get Version and GitCommit values from main.go.
Version = version
GitCommit = gitCommit

if err := rootCommand.Execute(); err != nil {
return err
Expand All @@ -47,3 +53,40 @@ func runRootCommand(cmd *cobra.Command, args []string) error {

return nil
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Display version information.",
Run: parseBaseCommand,
}

func parseBaseCommand(_ *cobra.Command, _ []string) {
printLogo()

fmt.Printf(
`faasd
Commit: %s
Version: %s
`, GitCommit, GetVersion())
}

func printLogo() {
logoText := aec.WhiteF.Apply(Logo)
fmt.Println(logoText)
}

// GetVersion get latest version
func GetVersion() string {
if len(Version) == 0 {
return "dev"
}
return Version
}

// Logo for version and root command
const Logo = ` __ _
/ _| __ _ __ _ ___ __| |
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
| _| (_| | (_| \__ \ (_| |
|_| \__,_|\__,_|___/\__,_|
`
46 changes: 0 additions & 46 deletions cmd/version.go

This file was deleted.

3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/alexellis/faasd/cmd"
)

// These values will be injected into these variables at the build time.
var (
// GitCommit Git Commit SHA
GitCommit string
Expand All @@ -14,7 +15,7 @@ var (
)

func main() {
if err := cmd.Execute(GitCommit, Version); err != nil {
if err := cmd.Execute(Version, GitCommit); err != nil {
os.Exit(1)
}
return
Expand Down

0 comments on commit 1784545

Please sign in to comment.