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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
affect people building from source.
- Migrate to `clap@v4`. This changes the way the help text is rendered. In terms
of behavior, nothing should change.
- Change some of the errors management to use the
[`anyhow` crate](https://crates.io/crates/anyhow). This should make the errors
affected by this change clearer and give more context.
- Rewrite how command versions are managed internally. This is a purely internal
change and should not affect users in any way.

<!-- section:previous-releases -->
## [v1.2.1] 2022-06-24
Expand Down
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ opt-level = 3
opt-level = 3

[dependencies]
anyhow = "1.0"
clap = { version = "4.0.32", features = ["cargo", "wrap_help"] }
toml = "0.5.10"
console = "0.15.3"
lazy_static = "1.4.0"
dialoguer = "0.10.2"
glob = "0.3.0"
thiserror = "1.0"

[dependencies.regex]
version = "1"
Expand All @@ -52,6 +54,7 @@ predicates = "2.1.5"
rand = "0.8"
serde = "1.0.152"
test-case = "2.2.2"
tempfile = "3"

[build-dependencies]
clap = { version = "4.0.32", features = ["cargo"] }
Expand Down
4 changes: 2 additions & 2 deletions src/checks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config;
use crate::environment;
use std::env;

use console::style;
Expand Down Expand Up @@ -28,7 +28,7 @@ pub fn check_shim_in_path() {
let path = env::var("PATH").unwrap_or_default();
let mut parts = env::split_paths(&path);

let shim_dir = config::shim_dir();
let shim_dir = environment::shim_dir();
if !parts.any(|part| part == shim_dir) {
let term = console::Term::stdout();
let (_, term_width) = term.size();
Expand Down
13 changes: 13 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::command_version::CommandVersionRegistry;
use crate::use_file;
use std::env;
use std::fs;
Expand All @@ -21,3 +22,15 @@ pub fn find_system_bin(command: &str) -> Option<PathBuf> {
.map(|p| fs::canonicalize(p).unwrap())
.find(|p| p != &current_exe)
}

pub fn find_selected_binary(
command_version_registry: &CommandVersionRegistry,
command_name: &str,
) -> Option<PathBuf> {
match find_selected_version(command_name) {
Some(version) => command_version_registry
.get(command_name, &version)
.map(|v| v.path),
None => find_system_bin(command_name),
}
}
Loading