diff --git a/Makefile b/Makefile index a6a4e9d..b667730 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SHELL := /bin/bash GITCOMMIT := $(shell git rev-parse HEAD) VERSION := "$(shell git describe --tags --abbrev=0)-$(shell git rev-parse --short HEAD)" -GO_CFLAGS=-X 'github.com/safedep/pmg/cmd/version.commit=$(GITCOMMIT)' -X 'github.com/safedep/pmg/cmd/version.version=$(VERSION)' +GO_CFLAGS=-X 'github.com/safedep/pmg/internal/version.Commit=$(GITCOMMIT)' -X 'github.com/safedep/pmg/internal/version.Version=$(VERSION)' GO_LDFLAGS=-ldflags "-w $(GO_CFLAGS)" .PHONY: all diff --git a/cmd/setup/setup.go b/cmd/setup/setup.go index 146d093..49f5c80 100644 --- a/cmd/setup/setup.go +++ b/cmd/setup/setup.go @@ -1,7 +1,11 @@ package setup import ( + "fmt" + "github.com/safedep/pmg/internal/alias" + "github.com/safedep/pmg/internal/ui" + "github.com/safedep/pmg/internal/version" "github.com/spf13/cobra" ) @@ -27,6 +31,8 @@ func NewInstallCommand() *cobra.Command { Short: "Install PMG aliases for package managers (npm, pnpm, pip)", Long: "Creates ~/.pmg.rc with package manager aliases and sources it in your shell config files (.bashrc, .zshrc, config.fish)", RunE: func(cmd *cobra.Command, args []string) error { + fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit)) + config := alias.DefaultConfig() rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName) if err != nil { @@ -44,6 +50,8 @@ func NewRemoveCommand() *cobra.Command { Use: "remove", Short: "Removes pmg aliases from the user's shell config file.", RunE: func(cmd *cobra.Command, args []string) error { + fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit)) + config := alias.DefaultConfig() rcFileManager, err := alias.NewDefaultRcFileManager(config.RcFileName) if err != nil { diff --git a/cmd/version/version.go b/cmd/version/version.go index 08669a0..354e4e8 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -3,30 +3,21 @@ package version import ( "fmt" "os" - runtimeDebug "runtime/debug" + "github.com/safedep/pmg/internal/ui" + "github.com/safedep/pmg/internal/version" "github.com/spf13/cobra" ) -var ( - version string - commit string -) - -func init() { - if version == "" { - buildInfo, _ := runtimeDebug.ReadBuildInfo() - version = buildInfo.Main.Version - } -} - func NewVersionCommand() *cobra.Command { return &cobra.Command{ Use: "version", Short: "Show version and build information", RunE: func(cmd *cobra.Command, args []string) error { - fmt.Fprintf(os.Stdout, "Version: %s\n", version) - fmt.Fprintf(os.Stdout, "CommitSHA: %s\n", commit) + fmt.Print(ui.GeneratePMGBanner(version.Version, version.Commit)) + + fmt.Fprintf(os.Stdout, "Version: %s\n", version.Version) + fmt.Fprintf(os.Stdout, "CommitSHA: %s\n", version.Commit) return nil }, diff --git a/internal/ui/banner.go b/internal/ui/banner.go new file mode 100644 index 0000000..2d6f572 --- /dev/null +++ b/internal/ui/banner.go @@ -0,0 +1,28 @@ +package ui + +import ( + "fmt" + + "github.com/fatih/color" +) + +var ( + brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink + whiteDim = color.New(color.Faint).SprintFunc() + whiteBold = color.New(color.Bold).SprintFunc() +) + +func GeneratePMGBanner(version, commit string) string { + var pmgASCIIText = ` +█▀█ █▀▄▀█ █▀▀ From SafeDep +█▀▀ █░▀░█ █▄█` // It should end here no \n + + if len(commit) >= 6 { + commit = commit[:6] + } + + return fmt.Sprintf("%s \t%s: %s %s: %s\n\n", brandPinkRed(pmgASCIIText), + whiteDim("version"), whiteBold(version), + whiteDim("commit"), whiteBold(commit), + ) +} diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..1c65173 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,15 @@ +package version + +import runtimeDebug "runtime/debug" + +var ( + Version string + Commit string +) + +func init() { + if Version == "" { + buildInfo, _ := runtimeDebug.ReadBuildInfo() + Version = buildInfo.Main.Version + } +} diff --git a/main.go b/main.go index 94667e9..dfaae53 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/safedep/pmg/config" "github.com/safedep/pmg/internal/analytics" "github.com/safedep/pmg/internal/ui" + appVersion "github.com/safedep/pmg/internal/version" "github.com/spf13/cobra" ) @@ -97,6 +98,12 @@ func main() { cmd.AddCommand(setup.NewSetupCommand()) cmd.AddCommand(setup.NewRemoveCommand()) + // Print Banner on --help / -h + cmd.SetHelpFunc(func(command *cobra.Command, args []string) { + fmt.Print(ui.GeneratePMGBanner(appVersion.Version, appVersion.Commit)) + fmt.Println(command.UsageString()) + }) + defer analytics.Close() analytics.TrackCommandRun()