This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
treefmt/internal/cli/cli.go
Brian McGee 4c45d2aa7e feat: allow missing formatters (#6)
Closes #3

Reviewed-on: #6
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2023-12-23 15:00:39 +00:00

28 lines
902 B
Go

package cli
import "github.com/charmbracelet/log"
var Cli = Options{}
type Options struct {
AllowMissingFormatter bool `default:"false" help:"Do not exit with error if a configured formatter is missing"`
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
TreeRoot string `type:"existingdir" default:"."`
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
Format Format `cmd:"" default:"."`
}
func (c *Options) ConfigureLogger() {
log.SetReportTimestamp(false)
if c.Verbosity == 0 {
log.SetLevel(log.WarnLevel)
} else if c.Verbosity == 1 {
log.SetLevel(log.InfoLevel)
} else if c.Verbosity >= 2 {
log.SetLevel(log.DebugLevel)
}
}