mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-19 12:36:38 +00:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
409fa5e642 | |||
03fe48db99 |
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
Version := $(shell git describe --tags --dirty)
|
Version := $(shell git describe --tags --dirty)
|
||||||
GitCommit := $(shell git rev-parse HEAD)
|
GitCommit := $(shell git rev-parse HEAD)
|
||||||
LDFLAGS := "-s -w -X pkg.Version=$(Version) -X pkg.GitCommit=$(GitCommit)"
|
LDFLAGS := "-s -w -X main.Version=$(Version) -X main.GitCommit=$(GitCommit)"
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: local
|
all: local
|
||||||
|
54
cmd/root.go
54
cmd/root.go
@ -1,6 +1,9 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/morikuni/aec"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +16,19 @@ func init() {
|
|||||||
rootCommand.AddCommand(installCmd)
|
rootCommand.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute() error {
|
var (
|
||||||
|
// GitCommit Git Commit SHA
|
||||||
|
GitCommit string
|
||||||
|
// Version version of the CLI
|
||||||
|
Version string
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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 {
|
if err := rootCommand.Execute(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -38,3 +53,40 @@ func runRootCommand(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
return nil
|
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 = ` __ _
|
||||||
|
/ _| __ _ __ _ ___ __| |
|
||||||
|
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
|
||||||
|
| _| (_| | (_| \__ \ (_| |
|
||||||
|
|_| \__,_|\__,_|___/\__,_|
|
||||||
|
`
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
10
main.go
10
main.go
@ -6,8 +6,16 @@ import (
|
|||||||
"github.com/alexellis/faasd/cmd"
|
"github.com/alexellis/faasd/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// These values will be injected into these variables at the build time.
|
||||||
|
var (
|
||||||
|
// GitCommit Git Commit SHA
|
||||||
|
GitCommit string
|
||||||
|
// Version version of the CLI
|
||||||
|
Version string
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(Version, GitCommit); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -1,24 +1 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
var (
|
|
||||||
// GitCommit Git Commit SHA
|
|
||||||
GitCommit string
|
|
||||||
// Version version of the CLI
|
|
||||||
Version string
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetVersion get latest version
|
|
||||||
func GetVersion() string {
|
|
||||||
if len(Version) == 0 {
|
|
||||||
return "dev"
|
|
||||||
}
|
|
||||||
return Version
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logo for version and root command
|
|
||||||
const Logo = ` __ _
|
|
||||||
/ _| __ _ __ _ ___ __| |
|
|
||||||
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
|
|
||||||
| _| (_| | (_| \__ \ (_| |
|
|
||||||
|_| \__,_|\__,_|___/\__,_|
|
|
||||||
`
|
|
||||||
|
Reference in New Issue
Block a user