Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added --latest option for outdated/upgrade #2667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
#[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,13 +44,13 @@
.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 {
self.display_json(outdated)?;

Check failure on line 51 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / nightly

mismatched types

Check failure on line 51 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / unit (ubuntu-latest)

mismatched types

Check failure on line 51 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / unit (macos-latest)

mismatched types
} else {
self.display(outdated)?;

Check failure on line 53 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / nightly

mismatched types

Check failure on line 53 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / unit (ubuntu-latest)

mismatched types

Check failure on line 53 in src/cli/outdated.rs

View workflow job for this annotation

GitHub Actions / unit (macos-latest)

mismatched types
}

Ok(())
Expand All @@ -49,14 +58,17 @@

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 @@
.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 @@

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 @@
}
}

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 @@
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
Loading