-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more config simplification #65
Conversation
Use the same semantic as `git` where `-C` is used to switch working directories. Simplify the startup sequence and responsibilities between the CLI and the engine. DRY "treefmt.toml" to config::FILENAME.
Since we do a lot of path manipulation, with commands changing directories and whatnot. It's probably easier to work with only absolute paths. If we can guarantee that, the rest will become easier.
By moving the resolution to parse time, it simplifies the core of the algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
None => return Err(anyhow!("treefmt.toml could not be found in {} and up. Use the --init option to create one.", cwd.display())) | ||
} | ||
return Err(anyhow!( | ||
"{} could not be found in {} and up. Use the --init option to create one.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if --init
shouldn't be init
as it's presented as a subcommand in the help menu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init
is our first design. But iirc, we want to avoid GitHub's CLI styling and that's why we ended up with --init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option is to not make it a sub-command but just a normal flag. And then deal with the command dispatch internally.
99% of the cases will be to run the formatter, which is the command we want to optimize for.
Now that all the uses of std::env::set_current_dir have been removed, we can add a bit of caching in that crate.
None => String::new(), | ||
}; | ||
// Set the command to run under its working directory. | ||
cmd_arg.current_dir(&c.work_dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this issue: rust-lang/rust#37868 related to Command's current_dir
, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Luckily all of our paths are absolute so we won't be affected by that issue :)
Get the absolute path of the formatter command during config load. If it could not be resolved, warn the user and drop that formatter from the list of commands that will get evaluated.
ce93070
to
449d466
Compare
There is only a single value attached to it.
7d4cc6a
to
3bb40df
Compare
If the manifest couldn't be loaded it's probably that the file format has changed. Ignore the error and continue.
Unify how we get back mtimes from files. Ideally, all the callers to get_mtime would be part of the cache and not split out like they currently are.
Co-authored-by: Basile Henry <bjm.henry@gmail.com>
Expose even further where the cache implementation is leaking
Generally move more invariants to the top to simplify the core algorithm. Any
Option type that can be removed is a good thing.