Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ title: Changelog
* `[Refactoring]` Move CLI startup flow from `cmd/lets/main.go` into `internal/cli/cli.go`, keeping `main.go` as a thin launcher.
* `[Added]` Add `lets self doc` command to open the online documentation in a browser.
* `[Added]` Show background update notifications for interactive sessions, with Homebrew-aware guidance and `LETS_CHECK_UPDATE` opt-out.
* `[Changed]` Centralize the `lets:` log prefix in the formatter and render debug messages in blue.

## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59)

Expand Down
22 changes: 11 additions & 11 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ func Main(version string, buildDate string) int {

command, args, err := rootCmd.Traverse(os.Args[1:])
if err != nil {
log.Errorf("lets: traverse commands error: %s", err)
log.Errorf("traverse commands error: %s", err)
return getExitCode(err, 1)
}

rootFlags, err := parseRootFlags(args)
if err != nil {
log.Errorf("lets: parse flags error: %s", err)
log.Errorf("parse flags error: %s", err)
return 1
}

if rootFlags.version {
if err := cmd.PrintVersionMessage(rootCmd); err != nil {
log.Errorf("lets: print version error: %s", err)
log.Errorf("print version error: %s", err)
return 1
}

Expand All @@ -79,7 +79,7 @@ func Main(version string, buildDate string) int {
cfg, err := config.Load(rootFlags.config, configDir, version)
if err != nil {
if failOnConfigError(rootCmd, command, rootFlags) {
log.Errorf("lets: config error: %s", err)
log.Errorf("config error: %s", err)
return 1
}
}
Expand All @@ -96,7 +96,7 @@ func Main(version string, buildDate string) int {
}

if err != nil {
log.Errorf("lets: can not create lets.yaml: %s", err)
log.Errorf("can not create lets.yaml: %s", err)
return 1
}

Expand All @@ -110,7 +110,7 @@ func Main(version string, buildDate string) int {
}

if err != nil {
log.Errorf("lets: can not self-upgrade binary: %s", err)
log.Errorf("can not self-upgrade binary: %s", err)
return 1
}

Expand All @@ -121,7 +121,7 @@ func Main(version string, buildDate string) int {

if showUsage {
if err := cmd.PrintRootHelpMessage(rootCmd); err != nil {
log.Errorf("lets: print help error: %s", err)
log.Errorf("print help error: %s", err)
return 1
}

Expand All @@ -137,7 +137,7 @@ func Main(version string, buildDate string) int {
executor.PrintDependencyTree(depErr, os.Stderr)
}

log.Errorf("lets: %s", err.Error())
log.Errorf("%s", err.Error())

return getExitCode(err, 1)
}
Expand All @@ -161,7 +161,7 @@ func getContext() context.Context {

go func() {
sig := <-ch
log.Printf("lets: signal received: %s", sig)
log.Printf("signal received: %s", sig)
cancel()
}()

Expand Down Expand Up @@ -211,7 +211,7 @@ func maybeStartUpdateCheck(
return nil, func() {}
}

log.Debugf("lets: start update check")
log.Debugf("start update check")

notifier, err := upgrade.NewUpdateNotifier(registry.NewGithubRegistry())
if err != nil {
Expand All @@ -227,7 +227,7 @@ func maybeStartUpdateCheck(
upgrade.LogUpdateCheckError(err)
}

log.Debugf("lets: update check done")
log.Debugf("update check done")

ch <- updateCheckResult{
notifier: notifier,
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *Command) GetEnv(cfg Config, builtinEnv map[string]string) (map[string]s

envFileEnv, err := envFiles.Load(cfg, filenameEnv)
if err != nil {
return nil, fmt.Errorf("lets: failed to resolve env_file for command '%s': %w", c.Name, err)
return nil, fmt.Errorf("failed to resolve env_file for command '%s': %w", c.Name, err)
}

resolvedEnv := envs.Dump()
Expand Down
3 changes: 1 addition & 2 deletions internal/config/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"path/filepath"

"github.com/fatih/color"
"github.com/lets-cli/lets/internal/config/path"
"github.com/lets-cli/lets/internal/util"
"github.com/lets-cli/lets/internal/workdir"
Expand Down Expand Up @@ -39,7 +38,7 @@ func FindConfig(configName string, configDir string) (PathInfo, error) {
return PathInfo{}, err
}

log.Debugf("%s", color.BlueString("lets: found %s config file in %s directory", configName, workDir))
log.Debugf("found %s config file in %s directory", configName, workDir)

configAbsPath := ""

Expand Down
32 changes: 26 additions & 6 deletions internal/logging/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/fatih/color"
log "github.com/sirupsen/logrus"
)

Expand All @@ -20,13 +21,36 @@ type Formatter struct{}
// Format implements the log.Formatter interface.
func (f *Formatter) Format(entry *log.Entry) ([]byte, error) {
buff := &bytes.Buffer{}
buff.WriteString(writeData(entry.Data))
buff.WriteString(entry.Message)
parts := []string{formatPrefix(entry)}

if data := writeData(entry.Data); data != "" {
parts = append(parts, data)
}

parts = append(parts, formatMessage(entry))

buff.WriteString(strings.Join(parts, " "))
buff.WriteString("\n")

return buff.Bytes(), nil
}

func formatPrefix(entry *log.Entry) string {
if entry.Level == log.DebugLevel {
return color.BlueString("lets:")
}

return "lets:"
}

func formatMessage(entry *log.Entry) string {
if entry.Level == log.DebugLevel {
return color.BlueString(entry.Message)
}

return entry.Message
}

func writeData(fields log.Fields) string {
var buff []string

Expand All @@ -39,9 +63,5 @@ func writeData(fields log.Fields) string {
}
}

if len(buff) > 0 {
buff = append(buff, "")
}

return strings.Join(buff, " ")
}
21 changes: 13 additions & 8 deletions internal/logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ func InitLogging(

// ExecLogger is used in Executor.
// If adds command chain in message like this:
// lets: [foo=>bar] message.
// [foo=>bar] message.
type ExecLogger struct {
log *log.Logger
// command name
name string
// lets: [a=>b]
// [a=>b]
prefix string
cache map[string]*ExecLogger
}

func NewExecLogger() *ExecLogger {
return &ExecLogger{
log: log.StandardLogger(),
prefix: color.BlueString("lets:"),
cache: make(map[string]*ExecLogger),
log: log.StandardLogger(),
cache: make(map[string]*ExecLogger),
}
}

Expand All @@ -71,19 +70,25 @@ func (l *ExecLogger) Child(name string) *ExecLogger {
l.cache[name] = &ExecLogger{
log: l.log,
name: name,
prefix: color.BlueString("lets: %s", color.GreenString("[%s]", name)),
prefix: color.GreenString("[%s]", name),
cache: make(map[string]*ExecLogger),
}

return l.cache[name]
}

func (l *ExecLogger) Info(format string, a ...any) {
format = fmt.Sprintf("%s %s", l.prefix, color.BlueString(format))
if l.prefix != "" {
format = fmt.Sprintf("%s %s", l.prefix, format)
}

l.log.Logf(log.InfoLevel, format, a...)
}

func (l *ExecLogger) Debug(format string, a ...any) {
format = fmt.Sprintf("%s %s", l.prefix, color.BlueString(format))
if l.prefix != "" {
format = fmt.Sprintf("%s %s", l.prefix, format)
}

l.log.Logf(log.DebugLevel, format, a...)
}
Loading
Loading