Skip to content

Commit

Permalink
feat: added replacing task order
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 21, 2024
1 parent 183fe5c commit ee5a20b
Show file tree
Hide file tree
Showing 43 changed files with 269 additions and 222 deletions.
14 changes: 7 additions & 7 deletions src/backend/aqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl AquaBackend {
return Ok(());
}
ctx.pr.set_message(format!("download {filename}"));
HTTP.download_file(url, &tarball_path, Some(ctx.pr.as_ref()))?;
HTTP.download_file(url, &tarball_path, Some(&ctx.pr))?;
Ok(())
}

Expand All @@ -255,7 +255,7 @@ impl AquaBackend {
AquaChecksumType::Http => checksum.url(pkg, v)?,
};
let checksum_path = tv.download_path().join(format!("{}.checksum", filename));
HTTP.download_file(&url, &checksum_path, Some(ctx.pr.as_ref()))?;
HTTP.download_file(&url, &checksum_path, Some(&ctx.pr))?;
self.cosign_checksums(ctx, pkg, v, tv, &checksum_path)?;
let mut checksum_file = file::read_to_string(&checksum_path)?;
if checksum.file_format() == "regexp" {
Expand Down Expand Up @@ -352,7 +352,7 @@ impl AquaBackend {
.map(|a| a.browser_download_url);
if let Some(url) = url {
let path = tv.download_path().join(asset);
HTTP.download_file(&url, &path, Some(ctx.pr.as_ref()))?;
HTTP.download_file(&url, &path, Some(&ctx.pr))?;
path.to_string_lossy().to_string()
} else {
warn!("no asset found for slsa verification of {tv}: {asset}");
Expand All @@ -362,7 +362,7 @@ impl AquaBackend {
"http" => {
let url = slsa.url(pkg, v)?;
let path = tv.download_path().join(filename);
HTTP.download_file(&url, &path, Some(ctx.pr.as_ref()))?;
HTTP.download_file(&url, &path, Some(&ctx.pr))?;
path.to_string_lossy().to_string()
}
t => {
Expand All @@ -379,7 +379,7 @@ impl AquaBackend {
.arg(format!("github.com/{repo}"))
.arg("--provenance-path")
.arg(provenance_path);
cmd = cmd.with_pr(ctx.pr.as_ref());
cmd = cmd.with_pr(&ctx.pr);
cmd.execute()?;
} else {
warn!("{tv} can be verified with slsa-verifier but slsa-verifier is not installed");
Expand Down Expand Up @@ -434,7 +434,7 @@ impl AquaBackend {
for opt in cosign.opts(pkg, v)? {
cmd = cmd.arg(opt);
}
cmd = cmd.with_pr(ctx.pr.as_ref());
cmd = cmd.with_pr(&ctx.pr);
cmd.execute()?;
} else {
warn!("{tv} can be verified with cosign but cosign is not installed");
Expand Down Expand Up @@ -463,7 +463,7 @@ impl AquaBackend {
}
let mut tar_opts = TarOptions {
format: format.parse().unwrap_or_default(),
pr: Some(ctx.pr.as_ref()),
pr: Some(&ctx.pr),
strip_components: 0,
};
if let AquaPackageType::GithubArchive = pkg.r#type {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl Backend for AsdfBackend {
sm.prepend_path(p);
}

let run_script = |script| sm.run_by_line(script, ctx.pr.as_ref());
let run_script = |script| sm.run_by_line(script, &ctx.pr);

if sm.script_exists(&Download) {
ctx.pr.set_message("bin/download".into());
Expand All @@ -344,7 +344,7 @@ impl Backend for AsdfBackend {
Ok(tv)
}

fn uninstall_version_impl(&self, pr: &dyn SingleReport, tv: &ToolVersion) -> Result<()> {
fn uninstall_version_impl(&self, pr: &Box<dyn SingleReport>, tv: &ToolVersion) -> Result<()> {
if self.plugin_path.join("bin/uninstall").exists() {
self.script_man_for_tv(tv)?
.run_by_line(&Script::Uninstall, pr)?;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Backend for CargoBackend {

cmd.arg("--root")
.arg(tv.install_path())
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
.prepend_path(self.dependency_toolset()?.list_paths())?
Expand Down
2 changes: 1 addition & 1 deletion src/backend/dotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Backend for DotnetBackend {
cli = cli.arg("--version").arg(&tv.version);
}

cli.with_pr(ctx.pr.as_ref())
cli.with_pr(&ctx.pr)
.envs(self.dependency_env()?)
.execute()?;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Backend for GemBackend {
// uninstalling the ruby version used to install the gem will break the
// gem. We should find a way to fix this.
// .arg("--env-shebang")
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.envs(self.dependency_env()?)
.execute()?;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Backend for GoBackend {
CmdLineRunner::new("go")
.arg("install")
.arg(format!("{}@{v}", self.tool_name()))
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.envs(self.dependency_env()?)
.env("GOBIN", tv.install_path().join("bin"))
.execute()
Expand Down
24 changes: 10 additions & 14 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub trait Backend: Debug + Send + Sync {
}
Ok(())
}
fn purge(&self, pr: &dyn SingleReport) -> eyre::Result<()> {
fn purge(&self, pr: &Box<dyn SingleReport>) -> eyre::Result<()> {
rmdir(&self.ba().installs_path, pr)?;
rmdir(&self.ba().cache_path, pr)?;
rmdir(&self.ba().downloads_path, pr)?;
Expand Down Expand Up @@ -401,7 +401,7 @@ pub trait Backend: Debug + Send + Sync {
let config = Config::get();
if self.is_version_installed(&tv, true) {
if ctx.force {
self.uninstall_version(&tv, ctx.pr.as_ref(), false)?;
self.uninstall_version(&tv, &ctx.pr, false)?;
} else {
return Ok(tv);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ pub trait Backend: Debug + Send + Sync {
) -> eyre::Result<()> {
CmdLineRunner::new(&*env::SHELL)
.env(&*env::PATH_KEY, plugins::core::path_env_with_tv_path(tv)?)
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.arg("-c")
.arg(script)
.envs(self.exec_env(&Config::get(), ctx.ts, tv)?)
Expand All @@ -466,7 +466,7 @@ pub trait Backend: Debug + Send + Sync {
fn uninstall_version(
&self,
tv: &ToolVersion,
pr: &dyn SingleReport,
pr: &Box<dyn SingleReport>,
dryrun: bool,
) -> eyre::Result<()> {
pr.set_message("uninstall".into());
Expand All @@ -491,14 +491,10 @@ pub trait Backend: Debug + Send + Sync {
rmdir(&tv.cache_path())?;
Ok(())
}
fn uninstall_version_impl(
&self,
_pr: &dyn SingleReport,
_tv: &ToolVersion,
) -> eyre::Result<()> {
fn uninstall_version_impl(&self, _pr: &Box<dyn SingleReport>, _tv: &ToolVersion) -> Result<()> {
Ok(())
}
fn list_bin_paths(&self, tv: &ToolVersion) -> eyre::Result<Vec<PathBuf>> {
fn list_bin_paths(&self, tv: &ToolVersion) -> Result<Vec<PathBuf>> {
match tv.request {
ToolRequest::System { .. } => Ok(vec![]),
_ => Ok(vec![tv.install_path().join("bin")]),
Expand All @@ -510,7 +506,7 @@ pub trait Backend: Debug + Send + Sync {
_config: &Config,
_ts: &Toolset,
_tv: &ToolVersion,
) -> eyre::Result<BTreeMap<String, String>> {
) -> Result<BTreeMap<String, String>> {
Ok(BTreeMap::new())
}

Expand Down Expand Up @@ -664,13 +660,13 @@ pub trait Backend: Debug + Send + Sync {
if let Some(checksum) = &tv.checksums.get(&filename) {
ctx.pr.set_message(format!("checksum {filename}"));
if let Some((algo, check)) = checksum.split_once(':') {
hash::ensure_checksum(file, check, Some(ctx.pr.as_ref()), algo)?;
hash::ensure_checksum(file, check, Some(&ctx.pr), algo)?;
} else {
bail!("Invalid checksum: {checksum}");
}
} else if SETTINGS.lockfile && SETTINGS.experimental {
ctx.pr.set_message(format!("generate checksum {filename}"));
let hash = hash::file_hash_sha256(file, Some(ctx.pr.as_ref()))?;
let hash = hash::file_hash_sha256(file, Some(&ctx.pr))?;
tv.checksums.insert(filename, format!("sha256:{hash}"));
}
Ok(())
Expand All @@ -688,7 +684,7 @@ fn find_match_in_list(list: &[String], query: &str) -> Option<String> {
}
}

fn rmdir(dir: &Path, pr: &dyn SingleReport) -> eyre::Result<()> {
fn rmdir(dir: &Path, pr: &Box<dyn SingleReport>) -> eyre::Result<()> {
if !dir.exists() {
return Ok(());
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Backend for NPMBackend {
.arg(tv.install_path())
.arg("--global")
.arg("--trust")
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.envs(ctx.ts.env_with_path(&config)?)
.env("BUN_INSTALL_GLOBAL_DIR", tv.install_path())
.env("BUN_INSTALL_BIN", tv.install_path().join("bin"))
Expand All @@ -91,7 +91,7 @@ impl Backend for NPMBackend {
.arg(format!("{}@{}", self.tool_name(), tv.version))
.arg("--prefix")
.arg(tv.install_path())
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
.prepend_path(self.dependency_toolset()?.list_paths())?
Expand Down
12 changes: 6 additions & 6 deletions src/backend/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Backend for PIPXBackend {
self,
&tv,
ctx.ts,
&*ctx.pr,
&ctx.pr,
)?;
if let Some(args) = tv.request.options().get("uvx_args") {
cmd = cmd.args(shell_words::split(args)?);
Expand All @@ -110,7 +110,7 @@ impl Backend for PIPXBackend {
self,
&tv,
ctx.ts,
&*ctx.pr,
&ctx.pr,
)?;
if let Some(args) = tv.request.options().get("pipx_args") {
cmd = cmd.args(shell_words::split(args)?);
Expand Down Expand Up @@ -149,14 +149,14 @@ impl PIPXBackend {
("install", format!("{}=={}", tv.ba().tool_name, tv.version)),
] {
let args = &["tool", cmd, tool];
Self::uvx_cmd(&config, args, &*b, &tv, &ts, &*pr)?.execute()?;
Self::uvx_cmd(&config, args, &*b, &tv, &ts, &pr)?.execute()?;
}
}
} else {
let pr = MultiProgressReport::get().add("reinstalling pipx tools");
for (b, tv) in pipx_tools {
let args = &["reinstall", &tv.ba().tool_name];
Self::pipx_cmd(&config, args, &*b, &tv, &ts, &*pr)?.execute()?;
Self::pipx_cmd(&config, args, &*b, &tv, &ts, &pr)?.execute()?;
}
}
Ok(())
Expand All @@ -168,7 +168,7 @@ impl PIPXBackend {
b: &dyn Backend,
tv: &ToolVersion,
ts: &Toolset,
pr: &'a dyn SingleReport,
pr: &'a Box<dyn SingleReport>,
) -> Result<CmdLineRunner<'a>> {
let mut cmd = CmdLineRunner::new("uv");
for arg in args {
Expand All @@ -189,7 +189,7 @@ impl PIPXBackend {
b: &dyn Backend,
tv: &ToolVersion,
ts: &Toolset,
pr: &'a dyn SingleReport,
pr: &'a Box<dyn SingleReport>,
) -> Result<CmdLineRunner<'a>> {
let mut cmd = CmdLineRunner::new("pipx");
for arg in args {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl SPMBackend {
package_repo.url.as_str(),
repo.dir.display(),
);
repo.clone(package_repo.url.as_str(), Some(ctx.pr.as_ref()))?;
repo.clone(package_repo.url.as_str(), Some(&ctx.pr))?;
}
debug!("Checking out revision: {revision}");
repo.update(Some(revision.to_string()))?;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl SPMBackend {
.arg(repo_dir)
.arg("--cache-path")
.arg(dirs::CACHE.join("spm"))
.with_pr(ctx.pr.as_ref())
.with_pr(&ctx.pr)
.prepend_path(self.dependency_toolset()?.list_paths())?
.execute()?;

Expand Down
4 changes: 2 additions & 2 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ impl Backend for UbiBackend {
ctx.pr
.set_message(format!("checksum verify {checksum_key}"));
if let Some((algo, check)) = checksum.split_once(':') {
hash::ensure_checksum(file, check, Some(ctx.pr.as_ref()), algo)?;
hash::ensure_checksum(file, check, Some(&ctx.pr), algo)?;
} else {
bail!("Invalid checksum: {checksum_key}");
}
} else if SETTINGS.lockfile && SETTINGS.experimental {
ctx.pr
.set_message(format!("checksum generate {checksum_key}"));
let hash = hash::file_hash_sha256(file, Some(ctx.pr.as_ref()))?;
let hash = hash::file_hash_sha256(file, Some(&ctx.pr))?;
tv.checksums.insert(checksum_key, format!("sha256:{hash}"));
}
Ok(())
Expand Down
12 changes: 0 additions & 12 deletions src/cli/config/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,11 @@ impl ConfigSet {
let mut container = config.as_item_mut();
let parts = self.key.split('.').collect::<Vec<&str>>();
for key in parts.iter().take(parts.len() - 1) {
<<<<<<< HEAD
container = container.as_table_mut().unwrap().entry(key).or_insert({
let mut t = toml_edit::Table::new();
t.set_implicit(true);
toml_edit::Item::Table(t)
});
=======
container = container
.as_table_mut()
.unwrap()
.entry(key)
.or_insert({
let mut t = toml_edit::Table::new();
t.set_implicit(true);
toml_edit::Item::Table(t)
});
>>>>>>> 01bd9dbb2 (fix: use implicit keys for `mise config set`)
}
let last_key = parts.last().unwrap();

Expand Down
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl Cli {
tmpdir: Default::default(),
tool: Default::default(),
keep_order_output: Default::default(),
task_prs: Default::default(),
}));
} else if let Some(cmd) = external::COMMANDS.get(&task) {
external::execute(
Expand Down
4 changes: 2 additions & 2 deletions src/cli/plugins/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl PluginsUninstall {
if plugin.is_installed() {
let prefix = format!("plugin:{}", style::eblue(&plugin.name()));
let pr = mpr.add(&prefix);
plugin.uninstall(pr.as_ref())?;
plugin.uninstall(&pr)?;
if self.purge {
let backend = backend::get(&plugin_name.into()).unwrap();
backend.purge(pr.as_ref())?;
backend.purge(&pr)?;
}
pr.finish_with_message("uninstalled".into());
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/plugins/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Update {
let prefix = format!("plugin:{}", style(plugin.name()).blue().for_stderr());
let pr = mpr.add(&prefix);
plugin
.update(pr.as_ref(), ref_)
.update(&pr, ref_)
.wrap_err_with(|| format!("[{plugin}] plugin update"))?;
Ok(())
})
Expand Down
2 changes: 1 addition & 1 deletion src/cli/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn delete(dry_run: bool, to_delete: Vec<(Arc<dyn Backend>, ToolVersion)>) -> Res
}
let pr = mpr.add(&prefix);
if dry_run || SETTINGS.yes || prompt::confirm_with_all(format!("remove {} ?", &tv))? {
p.uninstall_version(&tv, pr.as_ref(), dry_run)?;
p.uninstall_version(&tv, &pr, dry_run)?;
pr.finish();
}
}
Expand Down
Loading

0 comments on commit ee5a20b

Please sign in to comment.