Skip to content

Commit

Permalink
chore: Aliases -> Shims
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Oct 6, 2023
1 parent b784580 commit 00ca465
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ pub fn run(bin_path: String, args: Vec<String>) -> Result<()> {
let project_root = metadata::get_project_root()?;
let mut shell_paths = vec![];

let runbin = project_root.join(".bin/.bin").to_string_lossy().to_string();
let runbin = project_root.join(".bin/.shims").to_string_lossy().to_string();
if !system_shell_paths.contains(&runbin) {
shell_paths.push(runbin);
}

// https://github.com/dustinblackman/cargo-gha
let gha = project_root.join(".gha/.bin");
let gha = project_root.join(".gha/.shims");
if gha.exists() && !system_shell_paths.contains(&gha.to_string_lossy().to_string()) {
shell_paths.push(gha.to_string_lossy().to_string());
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use owo_colors::OwoColorize;
use crate::binary;
use crate::cargo_config;
use crate::metadata;
use crate::shell_alias;
use crate::shims;

#[cfg(test)]
#[path = "cli_integration_test.rs"]
Expand Down Expand Up @@ -43,7 +43,7 @@ fn run_binary(binary_name: String, args: Vec<String>) -> Result<()> {
}

let bin_path = binary::install(binary_package.unwrap().clone())?;
shell_alias::sync_aliases()?;
shims::sync()?;
binary::run(bin_path, args)?;

return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod binary;
mod cargo_config;
mod cli;
mod metadata;
mod shell_alias;
mod shims;

fn main() {
let res = cli::run();
Expand Down
12 changes: 6 additions & 6 deletions src/shell_alias.rs → src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use anyhow::Result;
use crate::metadata;

#[cfg(test)]
#[path = "shell_alias_test.rs"]
mod shell_alias_test;
#[path = "shims_test.rs"]
mod shims_test;

fn create_shell_script(binary: &str) -> Result<String> {
fn create_shim(binary: &str) -> Result<String> {
let shell = env::var("SHELL")
.unwrap_or("bash".to_string())
.split('/')
Expand All @@ -32,8 +32,8 @@ fi"#
return Ok(script);
}

pub fn sync_aliases() -> Result<()> {
let bin_dir = metadata::get_project_root()?.join(".bin/.bin");
pub fn sync() -> Result<()> {
let bin_dir = metadata::get_project_root()?.join(".bin/.shims");
if !bin_dir.exists() {
fs::create_dir_all(&bin_dir)?;
}
Expand All @@ -48,7 +48,7 @@ pub fn sync_aliases() -> Result<()> {
continue;
}

let script = create_shell_script(&bin)?;
let script = create_shim(&bin)?;
let bin_path = bin_dir.join(&bin);
if bin_path.exists() {
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/shell_alias_test.rs → src/shims_test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::*;

mod sync_shell_aliases {
mod sync_shims {
use super::super::metadata;
use super::*;

#[test]
fn it_creates_shell_aliases() {
let res = sync_aliases();
fn it_creates_shims() {
let res = sync();
let exists = metadata::get_project_root()
.unwrap()
.join(".bin/.bin/hello-world-first")
.join(".bin/.shims/hello-world-first")
.exists();

assert!(res.is_ok());
Expand Down

0 comments on commit 00ca465

Please sign in to comment.