Skip to content
Merged
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
6 changes: 3 additions & 3 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,19 +835,19 @@ impl TypedValueParser for VersionBumpSpecValueParser {

fn parse_ref(
&self,
_cmd: &clap::Command,
command: &clap::Command,
_arg: Option<&clap::Arg>,
value: &std::ffi::OsStr,
) -> Result<Self::Value, clap::Error> {
let raw = value.to_str().ok_or_else(|| {
clap::Error::raw(
command.clone().error(
ErrorKind::InvalidUtf8,
"`--bump` values must be valid UTF-8",
)
})?;

VersionBumpSpec::from_str(raw)
.map_err(|message| clap::Error::raw(ErrorKind::InvalidValue, message))
.map_err(|message| command.clone().error(ErrorKind::InvalidValue, message))
}

fn possible_values(&self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>> {
Expand Down
69 changes: 68 additions & 1 deletion crates/uv/tests/it/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use indoc::indoc;
use insta::assert_snapshot;

use uv_static::EnvVars;
use uv_test::uv_snapshot;
use uv_test::{apply_filters, uv_snapshot};

// Print the version
#[test]
Expand Down Expand Up @@ -1323,6 +1323,61 @@ requires-python = ">=3.12"
Ok(())
}

#[test]
fn bump_invalid_component_fails() -> Result<()> {
let context = uv_test::test_context!("3.12");

context
.temp_dir
.child("pyproject.toml")
.write_str(indoc! {r#"
[project]
name = "myproject"
version = "1.2.3"
requires-python = ">=3.12"
"#})?;

let output = uv_snapshot!(context.filters(), context.version()
.arg("--bump").arg("foo"), @"
exit_code: 2 (failure)
----- stderr -----
error: invalid bump component `foo`

Usage: uv version [OPTIONS] [VALUE]

For more information, try '--help'.
");

assert!(output.stderr.ends_with(b"\n"));

Ok(())
}

#[test]
fn bump_invalid_component_color() -> Result<()> {
let context = uv_test::test_context!("3.12");

let output = context
.version()
.arg("--bump")
.arg("foo")
.env_remove(EnvVars::NO_COLOR)
.env(EnvVars::CLICOLOR_FORCE, "1")
.output()?;

assert_eq!(output.status.code(), Some(2));
let stderr = apply_filters(
String::from_utf8_lossy(&output.stderr).into_owned(),
context.filters(),
);
assert_snapshot!(
format!("{stderr:?}"),
@r#""\u{1b}[1m\u{1b}[31merror:\u{1b}[0m invalid bump component `foo`\n\n\u{1b}[1m\u{1b}[32mUsage:\u{1b}[0m \u{1b}[1m\u{1b}[36muv version\u{1b}[0m \u{1b}[36m[OPTIONS]\u{1b}[0m \u{1b}[36m[VALUE]\u{1b}[0m\n\nFor more information, try '\u{1b}[1m\u{1b}[36m--help\u{1b}[0m'.\n""#
);

Ok(())
}

#[test]
fn bump_stable_with_value_fails() -> Result<()> {
let context = uv_test::test_context!("3.12");
Expand All @@ -1342,6 +1397,10 @@ requires-python = ">=3.12"
exit_code: 2 (failure)
----- stderr -----
error: `--bump stable` does not accept a value

Usage: uv version [OPTIONS] [VALUE]

For more information, try '--help'.
");
Ok(())
}
Expand All @@ -1365,6 +1424,10 @@ requires-python = ">=3.12"
exit_code: 2 (failure)
----- stderr -----
error: `--bump` values cannot be empty

Usage: uv version [OPTIONS] [VALUE]

For more information, try '--help'.
");
Ok(())
}
Expand All @@ -1388,6 +1451,10 @@ requires-python = ">=3.12"
exit_code: 2 (failure)
----- stderr -----
error: invalid numeric value `foo` for `--bump dev`

Usage: uv version [OPTIONS] [VALUE]

For more information, try '--help'.
");
Ok(())
}
Expand Down
Loading