Skip to content

Commit 0c93d98

Browse files
committedDec 23, 2023
feat: use a named type for Cli options
1 parent 6904097 commit 0c93d98

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed
 

‎internal/cli/cli.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,25 @@ package cli
22

33
import "github.com/charmbracelet/log"
44

5-
var Cli struct {
6-
Log LogOptions `embed:""`
5+
var Cli = Options{}
76

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

1213
Format Format `cmd:"" default:"."`
1314
}
1415

15-
type LogOptions struct {
16-
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
17-
}
18-
19-
func (lo *LogOptions) ConfigureLogger() {
16+
func (c *Options) ConfigureLogger() {
2017
log.SetReportTimestamp(false)
2118

22-
if lo.Verbosity == 0 {
19+
if c.Verbosity == 0 {
2320
log.SetLevel(log.WarnLevel)
24-
} else if lo.Verbosity == 1 {
21+
} else if c.Verbosity == 1 {
2522
log.SetLevel(log.InfoLevel)
26-
} else if lo.Verbosity >= 2 {
23+
} else if c.Verbosity >= 2 {
2724
log.SetLevel(log.DebugLevel)
2825
}
2926
}

‎internal/cli/format.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Format struct{}
1919
func (f *Format) Run() error {
2020
start := time.Now()
2121

22-
Cli.Log.ConfigureLogger()
22+
Cli.ConfigureLogger()
2323

2424
l := log.WithPrefix("format")
2525

0 commit comments

Comments
 (0)
Please sign in to comment.