Skip to content

Commit

Permalink
feat: added --latest option for outdated/upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Sep 27, 2024
1 parent 2281145 commit 45aaab0
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 40 deletions.
21 changes: 19 additions & 2 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ Arguments:
If not specified, all tools in global and local configs will be shown
Options:
-l, --latest
Compares against the latest versions available, not what matches the current config
For example, if you have `node = "20"` in your config by default `mise outdated` will only
show other 20.x versions, not 21.x or 22.x versions.
Using this flag, if there are 21.x or newer versions it will display those instead of 20.x.
-J, --json
Output in JSON format
Expand Down Expand Up @@ -1757,14 +1765,23 @@ Options:
-n, --dry-run
Just print what would be done, don't actually do it
-i, --interactive
Display multiselect menu to choose which tools to upgrade
-j, --jobs <JOBS>
Number of jobs to run in parallel
[default: 4]
[env: MISE_JOBS=]
-i, --interactive
Display multiselect menu to choose which tools to upgrade
-l, --latest
Upgrades to the latest version available, modifying mise.toml
For example, if you have `node = "20.0.0"` in your mise.toml but 22.1.0 is the latest available,
this will install 22.1.0 and set `node = "22.1.0"` in your config.
It keeps the same precision as what was there before, so if you instead had `node = "20"`, it
would change your config to `node = "22"`.
--raw
Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1
Expand Down
8 changes: 8 additions & 0 deletions docs/cli/outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Arguments:
If not specified, all tools in global and local configs will be shown
Options:
-l, --latest
Compares against the latest versions available, not what matches the current config
For example, if you have `node = "20"` in your config by default `mise outdated` will only
show other 20.x versions, not 21.x or 22.x versions.
Using this flag, if there are 21.x or newer versions it will display those instead of 20.x.
-J, --json
Output in JSON format
Expand Down
13 changes: 11 additions & 2 deletions docs/cli/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ Options:
-n, --dry-run
Just print what would be done, don't actually do it
-i, --interactive
Display multiselect menu to choose which tools to upgrade
-j, --jobs <JOBS>
Number of jobs to run in parallel
[default: 4]
[env: MISE_JOBS=]
-i, --interactive
Display multiselect menu to choose which tools to upgrade
-l, --latest
Upgrades to the latest version available, modifying mise.toml
For example, if you have `node = "20.0.0"` in your mise.toml but 22.1.0 is the latest available,
this will install 22.1.0 and set `node = "22.1.0"` in your config.
It keeps the same precision as what was there before, so if you instead had `node = "20"`, it
would change your config to `node = "22"`.
--raw
Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1
Expand Down
8 changes: 7 additions & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ cmd "outdated" help="Shows outdated tool versions" {
$ mise outdated --json
{"python": {"requested": "3.11", "current": "3.11.0", "latest": "3.11.1"}, ...}
"#
flag "-l --latest" help="Compares against the latest versions available, not what matches the current config" {
long_help "Compares against the latest versions available, not what matches the current config\n\nFor example, if you have `node = \"20\"` in your config by default `mise outdated` will only\nshow other 20.x versions, not 21.x or 22.x versions.\n\nUsing this flag, if there are 21.x or newer versions it will display those instead of 20.x."
}
flag "-J --json" help="Output in JSON format"
arg "[TOOL@VERSION]..." help="Tool(s) to show outdated versions for\ne.g.: node@20 python@3.10\nIf not specified, all tools in global and local configs will be shown" var=true
}
Expand Down Expand Up @@ -1214,10 +1217,13 @@ By default this command modifies ".mise.toml" in the current directory."#
cmd "upgrade" help="Upgrades outdated tool versions" {
alias "up"
flag "-n --dry-run" help="Just print what would be done, don't actually do it"
flag "-i --interactive" help="Display multiselect menu to choose which tools to upgrade"
flag "-j --jobs" help="Number of jobs to run in parallel\n[default: 4]" {
arg "<JOBS>"
}
flag "-i --interactive" help="Display multiselect menu to choose which tools to upgrade"
flag "-l --latest" help="Upgrades to the latest version available, modifying mise.toml" {
long_help "Upgrades to the latest version available, modifying mise.toml\n\nFor example, if you have `node = \"20.0.0\"` in your mise.toml but 22.1.0 is the latest available,\nthis will install 22.1.0 and set `node = \"22.1.0\"` in your config.\n\nIt keeps the same precision as what was there before, so if you instead had `node = \"20\"`, it\nwould change your config to `node = \"22\"`."
}
flag "--raw" help="Directly pipe stdin/stdout/stderr from plugin to user Sets --jobs=1"
arg "[TOOL@VERSION]..." help="Tool(s) to upgrade\ne.g.: node@20 python@3.10\nIf not specified, all current tools will be upgraded" var=true
}
Expand Down
39 changes: 31 additions & 8 deletions src/cli/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use eyre::Result;
use crate::backend::Backend;
use crate::cli::args::ToolArg;
use crate::config::Config;
use crate::toolset::{ToolVersion, ToolsetBuilder};
use crate::toolset::{ToolSource, ToolVersion, ToolsetBuilder};

/// Shows outdated tool versions
#[derive(Debug, clap::Args)]
Expand All @@ -19,6 +19,15 @@ pub struct Outdated {
#[clap(value_name = "TOOL@VERSION", verbatim_doc_comment)]
pub tool: Vec<ToolArg>,

/// Compares against the latest versions available, not what matches the current config
///
/// For example, if you have `node = "20"` in your config by default `mise outdated` will only
/// show other 20.x versions, not 21.x or 22.x versions.
///
/// Using this flag, if there are 21.x or newer versions it will display those instead of 20.x.
#[clap(long, short = 'l', verbatim_doc_comment)]
pub latest: bool,

/// Output in JSON format
#[clap(short = 'J', long, verbatim_doc_comment)]
pub json: bool,
Expand All @@ -35,7 +44,7 @@ impl Outdated {
.collect::<HashSet<_>>();
ts.versions
.retain(|_, tvl| tool_set.is_empty() || tool_set.contains(&tvl.backend));
let outdated = ts.list_outdated_versions();
let outdated = ts.list_outdated_versions(self.latest);
if outdated.is_empty() {
info!("All tools are up to date");
} else if self.json {
Expand All @@ -49,14 +58,17 @@ impl Outdated {

fn display(&self, outdated: OutputVec) -> Result<()> {
// TODO: make a generic table printer in src/ui/table
let plugins = outdated.iter().map(|(t, _, _)| t.id()).collect::<Vec<_>>();
let plugins = outdated
.iter()
.map(|(t, _, _, _)| t.id())
.collect::<Vec<_>>();
let requests = outdated
.iter()
.map(|(_, tv, _)| tv.request.version())
.map(|(_, tv, _, _)| tv.request.version())
.collect::<Vec<_>>();
let currents = outdated
.iter()
.map(|(t, tv, _)| {
.map(|(t, tv, _, _)| {
if t.is_version_installed(tv, true) {
tv.version.clone()
} else {
Expand All @@ -66,7 +78,7 @@ impl Outdated {
.collect::<Vec<_>>();
let latests = outdated
.iter()
.map(|(_, _, c)| c.clone())
.map(|(_, _, c, _)| c.clone())
.collect::<Vec<_>>();
let plugin_width = plugins
.iter()
Expand Down Expand Up @@ -113,11 +125,15 @@ impl Outdated {

fn display_json(&self, outdated: OutputVec) -> Result<()> {
let mut map = serde_json::Map::new();
for (t, tv, c) in outdated {
for (t, tv, c, s) in outdated {
let mut inner = serde_json::Map::new();
inner.insert("requested".to_string(), tv.request.version().into());
inner.insert("current".to_string(), tv.version.clone().into());
inner.insert("latest".to_string(), c.into());
inner.insert(
"source".to_string(),
serde_json::Value::from_iter(s.as_json().into_iter()),
);
map.insert(t.id().to_string(), serde_json::Value::Object(inner));
}
let json = serde_json::Value::Object(map);
Expand All @@ -126,7 +142,7 @@ impl Outdated {
}
}

type OutputVec = Vec<(Arc<dyn Backend>, ToolVersion, String)>;
type OutputVec = Vec<(Arc<dyn Backend>, ToolVersion, String, ToolSource)>;

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
Expand Down Expand Up @@ -170,4 +186,11 @@ mod tests {
assert_cli_snapshot!("outdated", "tiny", "--json");
change_installed_version("tiny", "3.0.0", "3.1.0");
}

#[test]
fn test_outdated_json_latest() {
reset();
assert_cli!("use", "tiny@2");
assert_cli_snapshot!("outdated", "tiny", "--json", "--latest");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ expression: output
"tiny": {
"current": "3.0.0",
"latest": "3.1.0",
"requested": "3"
"requested": "3",
"source": {
"path": "~/cwd/.test-tool-versions",
"type": ".tool-versions"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: src/cli/outdated.rs
expression: output
---
{
"tiny": {
"current": "2.1.0",
"latest": "3.1.0",
"requested": "2",
"source": {
"path": "~/cwd/.test-tool-versions",
"type": ".tool-versions"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: src/cli/upgrade.rs
expression: output
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: src/cli/upgrade.rs
expression: output
---
mise Would uninstall tiny@3.0.0
mise Would uninstall dummy@ref:master
mise Would install tiny@3.1.0
mise Would install dummy@2.0.0
Loading

0 comments on commit 45aaab0

Please sign in to comment.