mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-09 08:26:47 +00:00
Extract file for version command
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
f0172e618a
commit
17a5e2c625
60
cmd/root.go
60
cmd/root.go
@ -1,21 +1,9 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/alexellis/faasd/pkg"
|
|
||||||
"github.com/morikuni/aec"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// Version as per git repo
|
|
||||||
Version string
|
|
||||||
|
|
||||||
// GitCommit as per git repo
|
|
||||||
GitCommit string
|
|
||||||
)
|
|
||||||
|
|
||||||
// WelcomeMessage to introduce ofc-bootstrap
|
// WelcomeMessage to introduce ofc-bootstrap
|
||||||
const WelcomeMessage = "Welcome to faasd"
|
const WelcomeMessage = "Welcome to faasd"
|
||||||
|
|
||||||
@ -25,6 +13,14 @@ func init() {
|
|||||||
rootCommand.AddCommand(installCmd)
|
rootCommand.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Execute() error {
|
||||||
|
|
||||||
|
if err := rootCommand.Execute(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var rootCommand = &cobra.Command{
|
var rootCommand = &cobra.Command{
|
||||||
Use: "faasd",
|
Use: "faasd",
|
||||||
Short: "Start faasd",
|
Short: "Start faasd",
|
||||||
@ -35,41 +31,6 @@ faasd - serverless without Kubernetes
|
|||||||
SilenceUsage: true,
|
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 {
|
func runRootCommand(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
printLogo()
|
printLogo()
|
||||||
@ -77,8 +38,3 @@ func runRootCommand(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printLogo() {
|
|
||||||
logoText := aec.WhiteF.Apply(pkg.Logo)
|
|
||||||
fmt.Println(logoText)
|
|
||||||
}
|
|
||||||
|
30
cmd/version.go
Normal file
30
cmd/version.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/alexellis/faasd/pkg"
|
||||||
|
"github.com/morikuni/aec"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
`, pkg.GitCommit, pkg.GetVersion())
|
||||||
|
}
|
||||||
|
|
||||||
|
func printLogo() {
|
||||||
|
logoText := aec.WhiteF.Apply(pkg.Logo)
|
||||||
|
fmt.Println(logoText)
|
||||||
|
}
|
4
main.go
4
main.go
@ -4,13 +4,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/alexellis/faasd/cmd"
|
"github.com/alexellis/faasd/cmd"
|
||||||
"github.com/alexellis/faasd/pkg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.Execute(pkg.Version, pkg.GitCommit); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//GitCommit Git Commit SHA
|
// GitCommit Git Commit SHA
|
||||||
GitCommit string
|
GitCommit string
|
||||||
//Version version of the CLI
|
// Version version of the CLI
|
||||||
Version string
|
Version string
|
||||||
)
|
)
|
||||||
|
|
||||||
//GetVersion get latest version
|
// GetVersion get latest version
|
||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
if len(Version) == 0 {
|
if len(Version) == 0 {
|
||||||
return "dev"
|
return "dev"
|
||||||
@ -15,6 +15,7 @@ func GetVersion() string {
|
|||||||
return Version
|
return Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logo for version and root command
|
||||||
const Logo = ` __ _
|
const Logo = ` __ _
|
||||||
/ _| __ _ __ _ ___ __| |
|
/ _| __ _ __ _ ___ __| |
|
||||||
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
|
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user