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

Refactor away def_file module into CommandVersionRegistry #275

Merged
merged 17 commits into from
Jan 5, 2023

Conversation

dotboris
Copy link
Owner

@dotboris dotboris commented Dec 31, 2022

This is in preparation for fixing #274

At its core, this PR removes the def_file module in favor of a new command_version::CommandVersionRegistry type which manages the command version known by alt. This replacement works with the same file as before: $ALT_HOME/defs.toml. This new type wraps all operations around command versions and regroups all operations into a single module.

This refactor pulls all the various bits of code that operate on the old defs type into the CommandVersionRegistry type. This simplifies a lot of the code of the various commands who no longer have to fiddle with the internals of the defs.toml dictionary.

This comes with a few other refactors:

  • Some CLI errors are now managed using the anyhow crate. This is nicer than the old pattern of just calling .expect(...) or .unwrap(...). This should make the errors reported by alt a little clearer and they should include more context.
  • Rename config module to environment. Previously, the config module would only deal in paths like alt's home directory. The new module is now also able to load the CommandVersionRegistry from $ALT_HOME/defs.toml file. While environment is about as generic as config, matches more with the idea of "the environment alt runs in" which is what this module represents.
  • Replace existing CommandVersion from the scan module with the new CommandVersion type that's part of the new command_version module.
  • In the use_cmd module, replace the "system" magic string with an enum type that represents the possibility between using the system version of a command or to use a specific one.

The refactor here brings a new set of patterns for the code. It doesn't apply this to the whole codebase and focuses on what needs to change for #274 . For example, the error management with anyhow is how I want all the code to look but I didn't refactor it all.

@dotboris dotboris changed the title Store absolute path in definitions Refactor away def_file module into CommandVersionRegistry Jan 5, 2023
@dotboris dotboris marked this pull request as ready for review January 5, 2023 20:09
@dotboris dotboris merged commit 94a46fc into main Jan 5, 2023
@dotboris dotboris deleted the 274-def-abs-path branch January 5, 2023 20:14
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.

None yet

1 participant