Compare commits
1 Commits
c92a65f0b5
...
f230dae37b
Author | SHA1 | Date | |
---|---|---|---|
f230dae37b |
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
@ -8,6 +9,7 @@ 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"`
|
||||
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
|
||||
|
@ -179,6 +179,40 @@ func TestCache(t *testing.T) {
|
||||
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 TestBustCacheOnFormatterChange(t *testing.T) {
|
||||
as := require.New(t)
|
||||
|
||||
|
Reference in New Issue
Block a user