Compare commits
5 Commits
55ea0d7047
...
d9b59ee6c7
Author | SHA1 | Date | |
---|---|---|---|
d9b59ee6c7 | |||
aa15922550 | |||
a3ca7825a6 | |||
84629f7b94 | |||
aebbcfd4f1 |
@ -1,19 +1,21 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/alecthomas/kong"
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Cli = Options{}
|
var Cli = Options{}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
AllowMissingFormatter bool `default:"false" help:"Do not exit with error if a configured formatter is missing"`
|
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"`
|
WorkingDirectory kong.ChangeDirFlag `default:"." short:"C" help:"Run as if treefmt was started in the specified working directory instead of the current working directory"`
|
||||||
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
|
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
|
||||||
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI"`
|
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
|
||||||
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
|
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI"`
|
||||||
TreeRoot string `type:"existingdir" default:"."`
|
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
|
||||||
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
|
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:"."`
|
Format Format `cmd:"" default:"."`
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,7 @@ func (f *Format) Run() error {
|
|||||||
// update cache as paths are completed
|
// update cache as paths are completed
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
batchSize := 1024
|
batchSize := 1024
|
||||||
batch := make([]string, batchSize)
|
batch := make([]string, 0, batchSize)
|
||||||
batch = batch[:0]
|
|
||||||
|
|
||||||
var pending, completed, changes int
|
var pending, completed, changes int
|
||||||
|
|
||||||
|
@ -179,6 +179,40 @@ func TestCache(t *testing.T) {
|
|||||||
as.Contains(string(out), "0 files changed")
|
as.Contains(string(out), "0 files changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChangeWorkingDirectory(t *testing.T) {
|
||||||
|
as := require.New(t)
|
||||||
|
|
||||||
|
// capture current cwd, so we can replace it after the test is finished
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
as.NoError(err)
|
||||||
|
|
||||||
|
t.Cleanup(func() {
|
||||||
|
// return to the previous working directory
|
||||||
|
as.NoError(os.Chdir(cwd))
|
||||||
|
})
|
||||||
|
|
||||||
|
tempDir := test.TempExamples(t)
|
||||||
|
configPath := tempDir + "/treefmt.toml"
|
||||||
|
|
||||||
|
// test without any excludes
|
||||||
|
config := format.Config{
|
||||||
|
Formatters: map[string]*format.Formatter{
|
||||||
|
"echo": {
|
||||||
|
Command: "echo",
|
||||||
|
Includes: []string{"*"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
test.WriteConfig(t, configPath, config)
|
||||||
|
|
||||||
|
// by default, we look for ./treefmt.toml and use the cwd for the tree root
|
||||||
|
// this should fail if the working directory hasn't been changed first
|
||||||
|
out, err := cmd(t, "-C", tempDir)
|
||||||
|
as.NoError(err)
|
||||||
|
as.Contains(string(out), fmt.Sprintf("%d files changed", 29))
|
||||||
|
}
|
||||||
|
|
||||||
func TestFailOnChange(t *testing.T) {
|
func TestFailOnChange(t *testing.T) {
|
||||||
as := require.New(t)
|
as := require.New(t)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user