Accept --no-upgrade, --no-refresh, etc. on the CLI (#3328)

## Summary

We added `--no-X` variants for all other flags, but omitted these. Seems
more consistent to support them.

Closes https://github.com/astral-sh/uv/issues/1900.
This commit is contained in:
Charlie Marsh 2024-05-01 11:13:33 -07:00 committed by GitHub
parent 614c07329b
commit c6137702a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 75 additions and 35 deletions

View file

@ -17,13 +17,17 @@ pub enum Reinstall {
impl Reinstall {
/// Determine the reinstall strategy to use.
pub fn from_args(reinstall: bool, reinstall_package: Vec<PackageName>) -> Self {
if reinstall {
Self::All
} else if !reinstall_package.is_empty() {
Self::Packages(reinstall_package)
} else {
Self::None
pub fn from_args(reinstall: Option<bool>, reinstall_package: Vec<PackageName>) -> Self {
match reinstall {
Some(true) => Self::All,
Some(false) => Self::None,
None => {
if reinstall_package.is_empty() {
Self::None
} else {
Self::Packages(reinstall_package)
}
}
}
}
@ -53,13 +57,17 @@ pub enum Upgrade {
impl Upgrade {
/// Determine the upgrade strategy from the command-line arguments.
pub fn from_args(upgrade: bool, upgrade_package: Vec<PackageName>) -> Self {
if upgrade {
Self::All
} else if !upgrade_package.is_empty() {
Self::Packages(upgrade_package.into_iter().collect())
} else {
Self::None
pub fn from_args(upgrade: Option<bool>, upgrade_package: Vec<PackageName>) -> Self {
match upgrade {
Some(true) => Self::All,
Some(false) => Self::None,
None => {
if upgrade_package.is_empty() {
Self::None
} else {
Self::Packages(upgrade_package.into_iter().collect())
}
}
}
}