mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-19 19:44:40 +00:00
Better missing self update feature (#8337)
This commit is contained in:
parent
d53d580221
commit
e26eed10e4
4 changed files with 158 additions and 18 deletions
|
|
@ -408,7 +408,6 @@ pub enum Commands {
|
|||
Cache(CacheNamespace),
|
||||
/// Manage the uv executable.
|
||||
#[command(name = "self")]
|
||||
#[cfg(feature = "self-update")]
|
||||
Self_(SelfNamespace),
|
||||
/// Clear the cache, removing all entries or those linked to specific packages.
|
||||
#[command(hide = true)]
|
||||
|
|
@ -449,21 +448,18 @@ pub struct HelpArgs {
|
|||
}
|
||||
|
||||
#[derive(Args)]
|
||||
#[cfg(feature = "self-update")]
|
||||
pub struct SelfNamespace {
|
||||
#[command(subcommand)]
|
||||
pub command: SelfCommand,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
#[cfg(feature = "self-update")]
|
||||
pub enum SelfCommand {
|
||||
/// Update uv.
|
||||
Update(SelfUpdateArgs),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
#[cfg(feature = "self-update")]
|
||||
pub struct SelfUpdateArgs {
|
||||
/// Update to the specified version. If not provided, uv will update to the latest version.
|
||||
pub target_version: Option<String>,
|
||||
|
|
|
|||
|
|
@ -806,6 +806,13 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
|
|||
token,
|
||||
}),
|
||||
}) => commands::self_update(target_version, token, printer).await,
|
||||
#[cfg(not(feature = "self-update"))]
|
||||
Commands::Self_(_) => {
|
||||
anyhow::bail!(
|
||||
"uv was installed through an external package manager, and self-update \
|
||||
is not available. Please use your package manager to update uv."
|
||||
);
|
||||
}
|
||||
Commands::Version { output_format } => {
|
||||
commands::version(output_format, &mut stdout())?;
|
||||
Ok(ExitStatus::Success)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ fn help() {
|
|||
let context = TestContext::new_with_versions(&[]);
|
||||
|
||||
// The `uv help` command should show the long help message
|
||||
uv_snapshot!(context.filters(), context.help(), @r#"
|
||||
uv_snapshot!(context.filters(), context.help(), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -29,6 +29,7 @@ fn help() {
|
|||
build Build Python packages into source distributions and wheels
|
||||
publish Upload distributions to an index
|
||||
cache Manage uv's cache
|
||||
self Manage the uvcutable
|
||||
version Display uv's version
|
||||
generate-shell-completion Generate shell completion
|
||||
help Display documentation for a command
|
||||
|
|
@ -67,14 +68,14 @@ fn help() {
|
|||
|
||||
|
||||
----- stderr -----
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_flag() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("--help"), @r#"
|
||||
uv_snapshot!(context.filters(), context.command().arg("--help"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -98,6 +99,7 @@ fn help_flag() {
|
|||
build Build Python packages into source distributions and wheels
|
||||
publish Upload distributions to an index
|
||||
cache Manage uv's cache
|
||||
self Manage the uvcutable
|
||||
version Display uv's version
|
||||
help Display documentation for a command
|
||||
|
||||
|
|
@ -134,14 +136,14 @@ fn help_flag() {
|
|||
Use `uv help` for more details.
|
||||
|
||||
----- stderr -----
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_short_flag() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
|
||||
uv_snapshot!(context.filters(), context.command().arg("-h"), @r#"
|
||||
uv_snapshot!(context.filters(), context.command().arg("-h"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -165,6 +167,7 @@ fn help_short_flag() {
|
|||
build Build Python packages into source distributions and wheels
|
||||
publish Upload distributions to an index
|
||||
cache Manage uv's cache
|
||||
self Manage the uvcutable
|
||||
version Display uv's version
|
||||
help Display documentation for a command
|
||||
|
||||
|
|
@ -201,7 +204,7 @@ fn help_short_flag() {
|
|||
Use `uv help` for more details.
|
||||
|
||||
----- stderr -----
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -672,7 +675,7 @@ fn help_flag_subsubcommand() {
|
|||
fn help_unknown_subcommand() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("foobar"), @r#"
|
||||
uv_snapshot!(context.filters(), context.help().arg("foobar"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
|
@ -694,11 +697,12 @@ fn help_unknown_subcommand() {
|
|||
build
|
||||
publish
|
||||
cache
|
||||
self
|
||||
version
|
||||
generate-shell-completion
|
||||
"#);
|
||||
"###);
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("foo").arg("bar"), @r#"
|
||||
uv_snapshot!(context.filters(), context.help().arg("foo").arg("bar"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
|
@ -720,9 +724,10 @@ fn help_unknown_subcommand() {
|
|||
build
|
||||
publish
|
||||
cache
|
||||
self
|
||||
version
|
||||
generate-shell-completion
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -749,7 +754,7 @@ fn help_unknown_subsubcommand() {
|
|||
fn help_with_global_option() {
|
||||
let context = TestContext::new_with_versions(&[]);
|
||||
|
||||
uv_snapshot!(context.filters(), context.help().arg("--no-cache"), @r#"
|
||||
uv_snapshot!(context.filters(), context.help().arg("--no-cache"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -773,6 +778,7 @@ fn help_with_global_option() {
|
|||
build Build Python packages into source distributions and wheels
|
||||
publish Upload distributions to an index
|
||||
cache Manage uv's cache
|
||||
self Manage the uvcutable
|
||||
version Display uv's version
|
||||
generate-shell-completion Generate shell completion
|
||||
help Display documentation for a command
|
||||
|
|
@ -811,7 +817,7 @@ fn help_with_global_option() {
|
|||
|
||||
|
||||
----- stderr -----
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -853,7 +859,7 @@ fn help_with_no_pager() {
|
|||
|
||||
// We can't really test whether the --no-pager option works with a snapshot test.
|
||||
// It's still nice to have a test for the option to confirm the option exists.
|
||||
uv_snapshot!(context.filters(), context.help().arg("--no-pager"), @r#"
|
||||
uv_snapshot!(context.filters(), context.help().arg("--no-pager"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -877,6 +883,7 @@ fn help_with_no_pager() {
|
|||
build Build Python packages into source distributions and wheels
|
||||
publish Upload distributions to an index
|
||||
cache Manage uv's cache
|
||||
self Manage the uvcutable
|
||||
version Display uv's version
|
||||
generate-shell-completion Generate shell completion
|
||||
help Display documentation for a command
|
||||
|
|
@ -915,5 +922,5 @@ fn help_with_no_pager() {
|
|||
|
||||
|
||||
----- stderr -----
|
||||
"#);
|
||||
"###);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue