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

34 lines
1.4 KiB
Go
Raw Normal View History

2023-12-23 12:50:47 +00:00
package cli
import (
"github.com/alecthomas/kong"
"github.com/charmbracelet/log"
)
2023-12-23 12:50:47 +00:00
2023-12-23 12:56:17 +00:00
var Cli = Options{}
2023-12-23 12:50:47 +00:00
2023-12-23 12:56:17 +00:00
type Options struct {
AllowMissingFormatter bool `default:"false" help:"Do not exit with error if a configured formatter is missing"`
WorkingDirectory kong.ChangeDirFlag `default:"." short:"C" help:"Run as if treefmt was started in the specified working directory instead of the current working directory"`
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"`
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI"`
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
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"`
2023-12-23 12:50:47 +00:00
Format Format `cmd:"" default:"."`
}
func (c *Options) Configure() {
2023-12-23 12:50:47 +00:00
log.SetReportTimestamp(false)
2023-12-23 12:56:17 +00:00
if c.Verbosity == 0 {
2023-12-23 12:50:47 +00:00
log.SetLevel(log.WarnLevel)
2023-12-23 12:56:17 +00:00
} else if c.Verbosity == 1 {
2023-12-23 12:50:47 +00:00
log.SetLevel(log.InfoLevel)
2023-12-23 12:56:17 +00:00
} else if c.Verbosity >= 2 {
2023-12-23 12:50:47 +00:00
log.SetLevel(log.DebugLevel)
}
}