Skip to content

Commit

Permalink
simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed May 30, 2024
1 parent bc89625 commit 7f4697f
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions cli/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,21 @@ func (f *Format) Run() (err error) {
}
}

// search for the project root unless specified
// default the tree root to the directory containing the config file
if Cli.TreeRoot == "" {
// use the location of the treefmt.toml file by default
dir := filepath.Dir(Cli.ConfigFile)
Cli.TreeRoot = filepath.Dir(Cli.ConfigFile)
}

// search using the --tree-root-file if specified
if Cli.TreeRootFile != "" {
pwd, err := os.Getwd()
if err != nil {
return err
}
_, dir, err = findUp(pwd, Cli.TreeRootFile)
if err != nil {
return err
}
// search the tree root using the --tree-root-file if specified
if Cli.TreeRootFile != "" {
pwd, err := os.Getwd()
if err != nil {
return err
}
_, Cli.TreeRoot, err = findUp(pwd, Cli.TreeRootFile)
if err != nil {
return err
}

Cli.TreeRoot = dir
}

log.Debugf("config-file=%s tree-root=%s", Cli.ConfigFile, Cli.TreeRoot)
Expand Down

0 comments on commit 7f4697f

Please sign in to comment.