mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-08 16:06:47 +00:00
Alteration for version passing
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
03fe48db99
commit
409fa5e642
47
cmd/root.go
47
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,9 +23,12 @@ var (
|
|||||||
Version string
|
Version string
|
||||||
)
|
)
|
||||||
|
|
||||||
func Execute(gitCommit, version string) error {
|
// Execute faasd
|
||||||
GitCommit = gitCommit
|
func Execute(version, gitCommit string) error {
|
||||||
|
|
||||||
|
// Get Version and GitCommit values from main.go.
|
||||||
Version = version
|
Version = version
|
||||||
|
GitCommit = gitCommit
|
||||||
|
|
||||||
if err := rootCommand.Execute(); err != nil {
|
if err := rootCommand.Execute(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -47,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,46 +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
|
|
||||||
`, GitCommit, GetVersion())
|
|
||||||
}
|
|
||||||
|
|
||||||
func printLogo() {
|
|
||||||
logoText := aec.WhiteF.Apply(pkg.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 = ` __ _
|
|
||||||
/ _| __ _ __ _ ___ __| |
|
|
||||||
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
|
|
||||||
| _| (_| | (_| \__ \ (_| |
|
|
||||||
|_| \__,_|\__,_|___/\__,_|
|
|
||||||
`
|
|
3
main.go
3
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/alexellis/faasd/cmd"
|
"github.com/alexellis/faasd/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// These values will be injected into these variables at the build time.
|
||||||
var (
|
var (
|
||||||
// GitCommit Git Commit SHA
|
// GitCommit Git Commit SHA
|
||||||
GitCommit string
|
GitCommit string
|
||||||
@ -14,7 +15,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.Execute(GitCommit, Version); err != nil {
|
if err := cmd.Execute(Version, GitCommit); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user