mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-15 15:05:03 +00:00

Adds hidden `--preview` / `--no-preview` flags with `UV_PREVIEW` environment variable support. Copies the `PreviewMode` type from Ruff. Does a little bit of extra work to port `uv run` to the new settings model. Note we allow `uv run` invocations without preview and only use its presence to toggle an experimental warning. ## Test plan ``` ❯ cargo run -q -- run --no-workspace -- python --version warning: `uv run` is experimental and may change without warning. Python 3.12.2 ❯ cargo run -q -- run --no-workspace --preview -- python --version Python 3.12.2 ❯ UV_PREVIEW=1 cargo run -q -- run --no-workspace -- python --version Python 3.12.2 ```
37 lines
782 B
Rust
37 lines
782 B
Rust
use std::fmt::{Display, Formatter};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
pub enum PreviewMode {
|
|
#[default]
|
|
Disabled,
|
|
Enabled,
|
|
}
|
|
|
|
impl PreviewMode {
|
|
pub fn is_enabled(&self) -> bool {
|
|
matches!(self, Self::Enabled)
|
|
}
|
|
|
|
pub fn is_disabled(&self) -> bool {
|
|
matches!(self, Self::Disabled)
|
|
}
|
|
}
|
|
|
|
impl From<bool> for PreviewMode {
|
|
fn from(version: bool) -> Self {
|
|
if version {
|
|
PreviewMode::Enabled
|
|
} else {
|
|
PreviewMode::Disabled
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Display for PreviewMode {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Disabled => write!(f, "disabled"),
|
|
Self::Enabled => write!(f, "enabled"),
|
|
}
|
|
}
|
|
}
|