-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve version printing; color logo
- Loading branch information
Showing
6 changed files
with
141 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,81 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func NewVersionCommand(opts *Options) *cli.Command { | ||
actionOpts := &versionActionOpts{ | ||
Options: opts, | ||
} | ||
return &cli.Command{ | ||
Name: "version", | ||
Aliases: []string{"v"}, | ||
Usage: "Shows tool version", | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "ci", | ||
Usage: "print output using standard log and JSON format", | ||
Aliases: []string{"c"}, | ||
Action: func(_ *cli.Context, b bool) error { | ||
actionOpts.ci = b | ||
opts.Log = opts.Log.WithFormatter(pterm.LogFormatterJSON) | ||
return nil | ||
}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "v", | ||
Usage: "show more info", | ||
Destination: &actionOpts.v, | ||
DisableDefaultText: true, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "vv", | ||
Usage: "show much more info", | ||
Destination: &actionOpts.vv, | ||
DisableDefaultText: true, | ||
}, | ||
}, | ||
Action: func(_ *cli.Context) error { | ||
fmt.Printf("pkup-gen version: %s\n", opts.Version) | ||
return nil | ||
text, err := buildVersionOutput(actionOpts) | ||
fmt.Print(text) | ||
return err | ||
}, | ||
} | ||
} | ||
|
||
func buildVersionOutput(opts *versionActionOpts) (string, error) { | ||
data := getVersionData(opts) | ||
|
||
if opts.ci { | ||
byteData, err := json.Marshal(data) | ||
return string(byteData), err | ||
} | ||
|
||
text := "" | ||
for key, value := range data { | ||
text += fmt.Sprintf("%s: %s\n", key, value) | ||
} | ||
|
||
return text, nil | ||
} | ||
|
||
func getVersionData(opts *versionActionOpts) map[string]string { | ||
data := map[string]string{} | ||
data["version"] = opts.BuildVersion | ||
if opts.v { | ||
data["build-commit"] = opts.BuildCommit | ||
data["build-data"] = opts.BuildDate | ||
} else if opts.vv { | ||
data["build-commit"] = opts.BuildCommit | ||
data["build-data"] = opts.BuildDate | ||
data["build-arch"] = opts.BuildArch | ||
data["build-os"] = opts.BuildOs | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package logo | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pterm/pterm" | ||
) | ||
|
||
var ( | ||
pkupLayers = []string{ | ||
`.______ __ ___ __ __ .______`, | ||
`| _ \ | |/ / | | | | | _ \`, | ||
`| |_) | | ' / | | | | | |_) |`, | ||
`| ___/ | < | | | | | ___/`, | ||
`| | | . \ | '--' | | | `, | ||
`| _| |__|\__\ \______/ | _| `, | ||
` `, | ||
} | ||
genLayers = []string{ | ||
``, | ||
``, | ||
`__ _ ___ _ __`, | ||
`/ _' |/ _ \ '_ \`, | ||
`| (_| | __/ | | |`, | ||
`\__, |\___|_| |_|`, | ||
`|___/`, | ||
} | ||
) | ||
|
||
func Build() string { | ||
return fmt.Sprint( | ||
pkupLayers[0], genLayers[0], "\n", | ||
pkupLayers[1], genLayers[1], "\n", | ||
pkupLayers[2], pterm.Bold.Sprint(pterm.LightRed(genLayers[2])), "\n", | ||
pkupLayers[3], pterm.Bold.Sprint(pterm.LightRed(genLayers[3])), "\n", | ||
pkupLayers[4], pterm.Bold.Sprint(pterm.LightRed(genLayers[4])), "\n", | ||
pkupLayers[5], pterm.Bold.Sprint(pterm.LightRed(genLayers[5])), "\n", | ||
pkupLayers[6], pterm.Bold.Sprint(pterm.LightRed(genLayers[6])), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters