Extract file for version command

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2019-12-31 12:18:27 +00:00
parent f0172e618a
commit 17a5e2c625
4 changed files with 43 additions and 58 deletions

View File

@ -1,21 +1,9 @@
package cmd
import (
"fmt"
"github.com/alexellis/faasd/pkg"
"github.com/morikuni/aec"
"github.com/spf13/cobra"
)
var (
// Version as per git repo
Version string
// GitCommit as per git repo
GitCommit string
)
// WelcomeMessage to introduce ofc-bootstrap
const WelcomeMessage = "Welcome to faasd"
@ -25,6 +13,14 @@ func init() {
rootCommand.AddCommand(installCmd)
}
func Execute() error {
if err := rootCommand.Execute(); err != nil {
return err
}
return nil
}
var rootCommand = &cobra.Command{
Use: "faasd",
Short: "Start faasd",
@ -35,41 +31,6 @@ faasd - serverless without Kubernetes
SilenceUsage: true,
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display version information.",
Run: parseBaseCommand,
}
func getVersion() string {
if len(Version) != 0 {
return Version
}
return "dev"
}
func parseBaseCommand(_ *cobra.Command, _ []string) {
printLogo()
fmt.Printf(
`faasd
Commit: %s
Version: %s
`, pkg.GitCommit, pkg.GetVersion())
}
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
}
return nil
}
func runRootCommand(cmd *cobra.Command, args []string) error {
printLogo()
@ -77,8 +38,3 @@ func runRootCommand(cmd *cobra.Command, args []string) error {
return nil
}
func printLogo() {
logoText := aec.WhiteF.Apply(pkg.Logo)
fmt.Println(logoText)
}