use color_eyre::eyre::{Result, bail};
use crate::cli::args::ToolArg;
use crate::config::Config;
use crate::toolset::ToolRequest;
use crate::ui::multi_progress_report::MultiProgressReport;
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
pub struct Latest {
#[clap(value_name = "TOOL@VERSION")]
tool: ToolArg,
#[clap(hide = true)]
asdf_version: Option<String>,
#[clap(short, long)]
installed: bool,
}
impl Latest {
pub async fn run(self) -> Result<()> {
let config = Config::get().await?;
let mut prefix = match self.tool.tvr {
None => self.asdf_version,
Some(ToolRequest::Version { version, .. }) => Some(version),
_ => bail!("invalid version: {}", self.tool.style()),
};
let backend = self.tool.ba.backend()?;
let mpr = MultiProgressReport::get();
if let Some(plugin) = backend.plugin() {
plugin.ensure_installed(&config, &mpr, false, false).await?;
}
if let Some(v) = prefix {
prefix = Some(config.resolve_alias(&backend, &v).await?);
}
let latest_version = if self.installed {
backend.latest_installed_version(prefix)?
} else {
backend.latest_version(&config, prefix).await?
};
if let Some(version) = latest_version {
miseprintln!("{}", version);
}
Ok(())
}
}
static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
$ <bold>mise latest node@20</bold> # get the latest version of node 20
20.0.0
$ <bold>mise latest node</bold> # get the latest stable version of node
20.0.0
"#
);