🎨 CLI UX enhancements

This commit is contained in:
Ettore Di Giacinto
2022-04-22 11:41:02 +02:00
parent 6674abb256
commit 388a3e4471
3 changed files with 31 additions and 41 deletions

View File

@@ -35,9 +35,10 @@ const (
)
var license = []string{
"Luet Copyright (C) 2019-2022 Ettore Di Giacinto",
"Copyright (C) 2019-2022 Ettore Di Giacinto",
"This program comes with ABSOLUTELY NO WARRANTY.",
"This is free software, and you are welcome to redistribute it under certain conditions.",
"For documentation, visit https://luet.io.",
}
// Build time and commit information.
@@ -58,6 +59,8 @@ var RootCmd = &cobra.Command{
Short: "Container based package manager",
Long: `Luet is a single-binary package manager based on containers to build packages.
For documentation, visit https://luet.io.
To install a package:
$ luet install package
@@ -89,7 +92,7 @@ To build a package, from a tree definition:
util.DefaultContext = ctx
util.DisplayVersionBanner(util.DefaultContext, util.IntroScreen, version, license)
util.DisplayVersionBanner(util.DefaultContext, version, license)
viper.BindPFlag("plugin", cmd.Flags().Lookup("plugin"))
@@ -116,7 +119,7 @@ To build a package, from a tree definition:
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
util.HandleLock(util.DefaultContext)
util.HandleLock()
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)

View File

@@ -16,6 +16,7 @@
package util
import (
"fmt"
"os"
"strings"
@@ -26,7 +27,6 @@ import (
"github.com/mudler/luet/pkg/api/core/context"
"github.com/mudler/luet/pkg/api/core/template"
"github.com/mudler/luet/pkg/api/core/types"
"github.com/mudler/luet/pkg/installer"
)
@@ -54,38 +54,33 @@ func TemplateFolders(ctx *context.Context, i installer.BuildTreeResult, treePath
return templateFolders
}
func IntroScreen() {
luetLogo, _ := pterm.DefaultBigText.WithLetters(
pterm.NewLettersFromStringWithStyle("LU", pterm.NewStyle(pterm.FgLightMagenta)),
pterm.NewLettersFromStringWithStyle("ET", pterm.NewStyle(pterm.FgLightBlue))).
Srender()
func HandleLock() {
if os.Getenv("LUET_NOLOCK") == "true" {
return
}
pterm.DefaultCenter.Print(luetLogo)
if len(os.Args) == 0 {
return
}
pterm.DefaultCenter.Print(pterm.DefaultHeader.WithFullWidth().WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Sprint("Luet - 0-deps container-based package manager"))
}
func HandleLock(c types.Context) {
if os.Getenv("LUET_NOLOCK") != "true" {
if len(os.Args) > 1 {
for _, lockedCmd := range lockedCommands {
if os.Args[1] == lockedCmd {
s := single.New("luet")
if err := s.CheckLock(); err != nil && err == single.ErrAlreadyRunning {
c.Fatal("another instance of the app is already running, exiting")
fmt.Println("another instance of the app is already running, exiting")
os.Exit(1)
} else if err != nil {
// Another error occurred, might be worth handling it as well
c.Fatal("failed to acquire exclusive app lock:", err.Error())
fmt.Println("failed to acquire exclusive app lock:", err.Error())
os.Exit(1)
}
defer s.TryUnlock()
break
}
}
}
}
}
func DisplayVersionBanner(c *context.Context, banner func(), version func() string, license []string) {
func DisplayVersionBanner(c *context.Context, version func() string, license []string) {
display := false
if len(os.Args) > 1 {
for _, c := range bannerCommands {
@@ -95,15 +90,7 @@ func DisplayVersionBanner(c *context.Context, banner func(), version func() stri
}
}
if display {
if c.Config.General.Quiet {
pterm.Info.Printf("Luet %s\n", version())
pterm.Info.Println(strings.Join(license, "\n"))
} else {
banner()
pterm.DefaultCenter.Print(version())
for _, l := range license {
pterm.DefaultCenter.Print(l)
}
}
}
}

View File

@@ -334,7 +334,7 @@ func (l *Logger) Spinner() {
}
func (l *Logger) Screen(text string) {
pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(2).Println(text)
l.Infof(":::> %s", text)
}
func (l *Logger) SpinnerText(suffix, prefix string) {