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 5711caebb9 feat: support .gitignore files (#19)
Introduces a `--walk` flag which can be used to tell `treefmt` how to traverse the directory specified by `--tree-root`.

By default, it will attempt to use `git ls-files`. If this fails, it falls back to using the filesystem.

You can explicitly traverse the filesystem instead of using git by providing `--walk filesystem`.

Close #1

Reviewed-on: #19
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-11 20:52:22 +00:00

36 lines
1.6 KiB
Go

package cli
import (
"git.numtide.com/numtide/treefmt/internal/walk"
"github.com/alecthomas/kong"
"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."`
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:"."`
Walk walk.Type `enum:"auto,git,filesystem" default:"auto" help:"The method used to traverse the files within --tree-root. Currently supports 'auto', 'git' or 'filesystem'."`
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) Configure() {
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)
}
}