Skip to content

Commit

Permalink
remove &muts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 12, 2023
1 parent 07ab5bd commit 29ea4b2
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/cli/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ impl Asdf {
}
}

fn list_versions(mut config: Config, out: &mut Output, args: &Vec<String>) -> Result<()> {
fn list_versions(config: Config, out: &mut Output, args: &Vec<String>) -> Result<()> {
if args[2] == "all" {
let mut new_args: Vec<String> = vec!["rtx".into(), "ls-remote".into()];
if args.len() >= 3 {
new_args.push(args[3].clone());
}
return Cli::new().run(config, &new_args, out);
}
let ts = ToolsetBuilder::new().build(&mut config)?;
let ts = ToolsetBuilder::new().build(&config)?;
let mut versions = ts.list_installed_versions(&config)?;
let plugin = match args.len() {
3 => Some(&args[2]),
Expand Down
4 changes: 2 additions & 2 deletions src/cli/bin_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::toolset::ToolsetBuilder;
pub struct BinPaths {}

impl BinPaths {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
for p in ts.list_paths(&config) {
rtxprintln!(out, "{}", p.display());
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct Current {
}

impl Current {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
match &self.plugin {
Some(plugin_name) => {
let plugin_name = unalias_plugin(plugin_name);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/direnv/envrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{dirs, env};
pub struct Envrc {}

impl Envrc {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;

let envrc_path = env::RTX_TMP_DIR
.join("direnv")
Expand Down
4 changes: 2 additions & 2 deletions src/cli/direnv/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct DirenvWatches {
}

impl DirenvExec {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;

let mut cmd = env_cmd();

Expand Down
4 changes: 2 additions & 2 deletions src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{duration, env};
pub struct Doctor {}

impl Doctor {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
rtxprintln!(out, "{}", rtx_version());
rtxprintln!(out, "{}", build_info());
rtxprintln!(out, "{}", shell());
Expand Down
8 changes: 3 additions & 5 deletions src/cli/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ pub struct Env {
}

impl Env {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;

if self.json {
self.output_json(config, out, ts)
Expand Down
8 changes: 3 additions & 5 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ pub struct Exec {
}

impl Exec {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;
pub fn run(self, config: Config, _out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;

let (program, args) = parse_command(&env::SHELL, &self.command, &self.c);
let env = ts.env_with_path(&config);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub struct HookEnv {
}

impl HookEnv {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
let shell = get_shell(self.shell).expect("no shell provided, use `--shell=zsh`");
out.stdout.write(hook_env::clear_old_env(&*shell));
let mut env = ts.env(&config);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ impl Install {

Ok(())
}
fn install_runtimes(&self, mut config: Config, runtimes: &[ToolArg]) -> Result<()> {
fn install_runtimes(&self, config: Config, runtimes: &[ToolArg]) -> Result<()> {
let mpr = MultiProgressReport::new(&config.settings);
let mut ts = ToolsetBuilder::new()
.with_latest_versions()
.build(&mut config)?;
let tool_versions = self.get_requested_tool_versions(&mut config, &ts, runtimes, &mpr)?;
.build(&config)?;
let tool_versions = self.get_requested_tool_versions(&config, &ts, runtimes, &mpr)?;
if tool_versions.is_empty() {
warn!("no runtimes to install");
warn!("specify a version with `rtx install <PLUGIN>@<VERSION>`");
Expand Down
4 changes: 2 additions & 2 deletions src/cli/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Latest {
}

impl Latest {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut prefix = match self.tool.tvr {
None => self.asdf_version,
Some(ToolVersionRequest::Version(_, version)) => Some(version),
Expand All @@ -37,7 +37,7 @@ impl Latest {
};

let plugin = config.get_or_create_plugin(&self.tool.plugin);
plugin.ensure_installed(&mut config, None, false)?;
plugin.ensure_installed(&config, None, false)?;
if let Some(v) = prefix {
prefix = Some(config.resolve_alias(plugin.name(), &v)?);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn get_parent_path() -> Result<PathBuf> {

#[allow(clippy::too_many_arguments)]
pub fn local(
mut config: Config,
config: Config,
out: &mut Output,
path: &Path,
runtime: Vec<ToolArg>,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn local(
return Ok(());
}
let pin = pin || (config.settings.asdf_compat && !fuzzy);
cf.add_runtimes(&mut config, &runtimes, pin)?;
cf.add_runtimes(&config, &runtimes, pin)?;
let tools = runtimes.iter().map(|r| r.to_string()).join(" ");
rtxprintln!(
out,
Expand Down
4 changes: 2 additions & 2 deletions src/cli/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ pub struct Ls {
}

impl Ls {
pub fn run(mut self, mut config: Config, out: &mut Output) -> Result<()> {
pub fn run(mut self, config: Config, out: &mut Output) -> Result<()> {
self.plugin = self
.plugin
.clone()
.or(self.plugin_flag.clone())
.map(|p| PluginName::from(unalias_plugin(&p)));
self.verify_plugin(&config)?;

let mut runtimes = self.get_runtime_list(&mut config)?;
let mut runtimes = self.get_runtime_list(&config)?;
if self.current || self.global {
// TODO: global is a little weird: it will show global versions as the active ones even if
// they're overridden locally
Expand Down
4 changes: 2 additions & 2 deletions src/cli/ls_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct LsRemote {
}

impl LsRemote {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
if let Some(plugin) = self.get_plugin(&mut config)? {
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
if let Some(plugin) = self.get_plugin(&config)? {
self.run_single(config, out, plugin)
} else {
self.run_all(config, out)
Expand Down
6 changes: 2 additions & 4 deletions src/cli/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ pub struct Outdated {
}

impl Outdated {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
let tool_set = self
.tool
.iter()
Expand Down
20 changes: 8 additions & 12 deletions src/cli/plugins/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ pub struct PluginsInstall {
}

impl PluginsInstall {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
pub fn run(self, config: Config, _out: &mut Output) -> Result<()> {
let mpr = MultiProgressReport::new(&config.settings);
if self.all {
return self.install_all_missing_plugins(config, mpr);
}
let (name, git_url) = get_name_and_url(&self.new_plugin.clone().unwrap(), &self.git_url)?;
if git_url.is_some() {
self.install_one(&mut config, name, git_url, &mpr)?;
self.install_one(&config, name, git_url, &mpr)?;
} else {
let mut plugins: Vec<PluginName> = vec![name];
if let Some(second) = self.git_url.clone() {
Expand All @@ -66,13 +66,9 @@ impl PluginsInstall {
Ok(())
}

fn install_all_missing_plugins(
&self,
mut config: Config,
mpr: MultiProgressReport,
) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
let missing_plugins = ts.list_missing_plugins(&mut config);
fn install_all_missing_plugins(&self, config: Config, mpr: MultiProgressReport) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
let missing_plugins = ts.list_missing_plugins(&config);
if missing_plugins.is_empty() {
warn!("all plugins already installed");
}
Expand All @@ -82,12 +78,12 @@ impl PluginsInstall {

fn install_many(
&self,
mut config: Config,
config: Config,
plugins: Vec<PluginName>,
mpr: MultiProgressReport,
) -> Result<()> {
for plugin in plugins {
self.install_one(&mut config, plugin, None, &mpr)?;
self.install_one(&config, plugin, None, &mpr)?;
}
Ok(())
// TODO: run in parallel
Expand All @@ -97,7 +93,7 @@ impl PluginsInstall {
// .install(|| -> Result<()> {
// plugins
// .into_par_iter()
// .map(|plugin| self.install_one(&mut config, plugin, None, &mpr))
// .map(|plugin| self.install_one(&config, plugin, None, &mpr))
// .collect::<Result<Vec<_>>>()?;
// Ok(())
// })
Expand Down
4 changes: 2 additions & 2 deletions src/cli/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct Prune {
}

impl Prune {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, _out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;
let mut to_delete = ts
.list_installed_versions(&config)?
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions src/cli/reshim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct Reshim {
}

impl Reshim {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&mut config)?;
pub fn run(self, config: Config, _out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new().build(&config)?;

shims::reshim(&config, &ts)
}
Expand Down
8 changes: 3 additions & 5 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ pub struct Shell {
}

impl Shell {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
if !config.is_activated() {
err_inactive()?;
}

let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;

let shell = get_shell(None).expect("no shell detected");

Expand Down
6 changes: 3 additions & 3 deletions src/cli/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Uninstall {
}

impl Uninstall {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
pub fn run(self, config: Config, _out: &mut Output) -> Result<()> {
let runtimes = ToolArg::double_tool_condition(&self.tool);

let mut tool_versions = vec![];
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Uninstall {
vec![tvr.resolve(&config, tool.clone(), Default::default(), false)?]
}
None => {
let ts = ToolsetBuilder::new().build(&mut config)?;
let ts = ToolsetBuilder::new().build(&config)?;
match ts.versions.get(&a.plugin) {
Some(tvl) => tvl.versions.clone(),
None => bail!(
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Uninstall {
pr.finish_with_message("uninstalled");
}

let ts = ToolsetBuilder::new().build(&mut config)?;
let ts = ToolsetBuilder::new().build(&config)?;
shims::reshim(&config, &ts).wrap_err("failed to reshim")?;
runtime_symlinks::rebuild(&config)?;

Expand Down
8 changes: 3 additions & 5 deletions src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ pub struct Upgrade {
}

impl Upgrade {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
let tool_set = self
.tool
.iter()
Expand All @@ -45,7 +43,7 @@ impl Upgrade {
if outdated.is_empty() {
info!("All tools are up to date");
} else {
self.upgrade(&mut config, outdated, out)?;
self.upgrade(&config, outdated, out)?;
}

Ok(())
Expand Down
8 changes: 3 additions & 5 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ pub struct Use {
}

impl Use {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;

ts.versions
.retain(|_, tvl| self.tool.iter().any(|t| t.plugin == tvl.plugin_name));
Expand Down
4 changes: 2 additions & 2 deletions src/cli/where.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ pub struct Where {
}

impl Where {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let runtime = match self.tool.tvr {
None => match self.asdf_version {
Some(version) => self.tool.with_version(&version),
None => {
let ts = ToolsetBuilder::new()
.with_args(&[self.tool.clone()])
.build(&mut config)?;
.build(&config)?;
let v = ts
.versions
.get(&self.tool.plugin)
Expand Down
4 changes: 2 additions & 2 deletions src/cli/which.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub struct Which {
}

impl Which {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = self.get_toolset(&mut config)?;
pub fn run(self, config: Config, out: &mut Output) -> Result<()> {
let ts = self.get_toolset(&config)?;

match ts.which(&config, &self.bin_name) {
Some((p, tv)) => {
Expand Down
Loading

0 comments on commit 29ea4b2

Please sign in to comment.