Skip to content

Commit

Permalink
feat: use a named type for Cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmcgee committed Dec 23, 2023
1 parent 6904097 commit 0c93d98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@ package cli

import "github.com/charmbracelet/log"

var Cli struct {
Log LogOptions `embed:""`
var Cli = Options{}

type Options struct {
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
TreeRoot string `type:"existingdir" default:"."`
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`

Format Format `cmd:"" default:"."`
}

type LogOptions struct {
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
}

func (lo *LogOptions) ConfigureLogger() {
func (c *Options) ConfigureLogger() {
log.SetReportTimestamp(false)

if lo.Verbosity == 0 {
if c.Verbosity == 0 {
log.SetLevel(log.WarnLevel)
} else if lo.Verbosity == 1 {
} else if c.Verbosity == 1 {
log.SetLevel(log.InfoLevel)
} else if lo.Verbosity >= 2 {
} else if c.Verbosity >= 2 {
log.SetLevel(log.DebugLevel)
}
}
2 changes: 1 addition & 1 deletion internal/cli/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Format struct{}
func (f *Format) Run() error {
start := time.Now()

Cli.Log.ConfigureLogger()
Cli.ConfigureLogger()

l := log.WithPrefix("format")

Expand Down

0 comments on commit 0c93d98

Please sign in to comment.