Skip to content
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

Merged
merged 12 commits into from
Feb 22, 2021
Merged

more config simplification #65

merged 12 commits into from
Feb 22, 2021

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Feb 22, 2021

Generally move more invariants to the top to simplify the core algorithm. Any
Option type that can be removed is a good thing.

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.
Copy link
Contributor

@basile-henry basile-henry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

README.md Outdated Show resolved Hide resolved
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.",
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

src/command/mod.rs Outdated Show resolved Hide resolved
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);
Copy link
Contributor

@Rizary Rizary Feb 22, 2021

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?

Copy link
Member Author

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.
There is only a single value attached to it.
zimbatm and others added 6 commits February 22, 2021 15:42
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
@zimbatm zimbatm merged commit 7a95af7 into master Feb 22, 2021
@zimbatm zimbatm deleted the config-simplifications branch February 22, 2021 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants