-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2129
- Loading branch information
Showing
10 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `mise sync ruby` | ||
|
||
- **Usage**: `mise sync ruby [--brew]` | ||
- **Source code**: [`src/cli/sync/ruby.rs`](https://github.com/jdx/mise/blob/main/src/cli/sync/ruby.rs) | ||
|
||
Symlinks all ruby tool versions from an external tool into mise | ||
|
||
## Flags | ||
|
||
### `--brew` | ||
|
||
Get tool versions from Homebrew | ||
|
||
Examples: | ||
|
||
``` | ||
brew install ruby | ||
mise sync ruby --brew | ||
mise use -g ruby - Use the latest version of Ruby installed by Homebrew | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::path::PathBuf; | ||
|
||
use eyre::Result; | ||
use itertools::sorted; | ||
|
||
use crate::{backend, cmd, config, dirs, file}; | ||
|
||
/// Symlinks all ruby tool versions from an external tool into mise | ||
#[derive(Debug, clap::Args)] | ||
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)] | ||
pub struct SyncRuby { | ||
#[clap(flatten)] | ||
_type: SyncRubyType, | ||
} | ||
|
||
#[derive(Debug, clap::Args)] | ||
#[group(required = true, multiple = true)] | ||
pub struct SyncRubyType { | ||
/// Get tool versions from Homebrew | ||
#[clap(long)] | ||
brew: bool, | ||
} | ||
|
||
impl SyncRuby { | ||
pub fn run(self) -> Result<()> { | ||
if self._type.brew { | ||
self.run_brew()?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn run_brew(&self) -> Result<()> { | ||
let ruby = backend::get(&"ruby".into()).unwrap(); | ||
|
||
let brew_prefix = PathBuf::from(cmd!("brew", "--prefix").read()?).join("opt"); | ||
let installed_versions_path = dirs::INSTALLS.join("ruby"); | ||
|
||
file::remove_symlinks_with_target_prefix(&installed_versions_path, &brew_prefix)?; | ||
|
||
let subdirs = file::dir_subdirs(&brew_prefix)?; | ||
for entry in sorted(subdirs) { | ||
if entry.starts_with(".") { | ||
continue; | ||
} | ||
if !entry.starts_with("ruby@") { | ||
continue; | ||
} | ||
let v = entry.trim_start_matches("ruby@"); | ||
if ruby.create_symlink(v, &brew_prefix.join(&entry))?.is_some() { | ||
miseprintln!("Synced ruby@{} from Homebrew", v); | ||
} | ||
} | ||
|
||
config::rebuild_shims_and_runtime_symlinks(&[]) | ||
} | ||
} | ||
|
||
static AFTER_LONG_HELP: &str = color_print::cstr!( | ||
r#"<bold><underline>Examples:</underline></bold> | ||
$ <bold>brew install ruby</bold> | ||
$ <bold>mise sync ruby --brew</bold> | ||
$ <bold>mise use -g ruby</bold> - Use the latest version of Ruby installed by Homebrew | ||
"# | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters