feat: use a named type for Cli options
This commit is contained in:
parent
6904097171
commit
0c93d98483
|
@ -2,9 +2,10 @@ package cli
|
||||||
|
|
||||||
import "github.com/charmbracelet/log"
|
import "github.com/charmbracelet/log"
|
||||||
|
|
||||||
var Cli struct {
|
var Cli = Options{}
|
||||||
Log LogOptions `embed:""`
|
|
||||||
|
|
||||||
|
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"`
|
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
|
||||||
TreeRoot string `type:"existingdir" default:"."`
|
TreeRoot string `type:"existingdir" default:"."`
|
||||||
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
|
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
|
||||||
|
@ -12,18 +13,14 @@ var Cli struct {
|
||||||
Format Format `cmd:"" default:"."`
|
Format Format `cmd:"" default:"."`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogOptions struct {
|
func (c *Options) ConfigureLogger() {
|
||||||
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() {
|
|
||||||
log.SetReportTimestamp(false)
|
log.SetReportTimestamp(false)
|
||||||
|
|
||||||
if lo.Verbosity == 0 {
|
if c.Verbosity == 0 {
|
||||||
log.SetLevel(log.WarnLevel)
|
log.SetLevel(log.WarnLevel)
|
||||||
} else if lo.Verbosity == 1 {
|
} else if c.Verbosity == 1 {
|
||||||
log.SetLevel(log.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
} else if lo.Verbosity >= 2 {
|
} else if c.Verbosity >= 2 {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ type Format struct{}
|
||||||
func (f *Format) Run() error {
|
func (f *Format) Run() error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
Cli.Log.ConfigureLogger()
|
Cli.ConfigureLogger()
|
||||||
|
|
||||||
l := log.WithPrefix("format")
|
l := log.WithPrefix("format")
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user