Skip to content

Commit

Permalink
Require --preview for ruff server (#10368)
Browse files Browse the repository at this point in the history
## Summary

Fixes #10367.

While the server is still in an unstable state, requiring a `--preview`
flag would be a good way to indicate this to end users.
  • Loading branch information
snowsignal authored Mar 13, 2024
1 parent 3243906 commit e832327
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,11 @@ pub struct FormatCommand {
}

#[derive(Clone, Debug, clap::Parser)]
pub struct ServerCommand;
pub struct ServerCommand {
/// Enable preview mode; required for regular operation
#[arg(long)]
pub(crate) preview: bool,
}

#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum HelpFormat {
Expand Down
6 changes: 5 additions & 1 deletion crates/ruff/src/commands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use tracing_subscriber::{
};
use tracing_tree::time::Uptime;

pub(crate) fn run_server(log_level: LogLevel) -> Result<ExitStatus> {
pub(crate) fn run_server(preview: bool, log_level: LogLevel) -> Result<ExitStatus> {
if !preview {
tracing::error!("--preview needs to be provided as a command line argument while the server is still unstable.\nFor example: `ruff server --preview`");
return Ok(ExitStatus::Error);
}
let trace_level = if log_level == LogLevel::Verbose {
Level::TRACE
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ fn format(args: FormatCommand, global_options: GlobalConfigArgs) -> Result<ExitS

#[allow(clippy::needless_pass_by_value)] // TODO: remove once we start taking arguments from here
fn server(args: ServerCommand, log_level: LogLevel) -> Result<ExitStatus> {
let ServerCommand {} = args;
commands::server::run_server(log_level)
let ServerCommand { preview } = args;
commands::server::run_server(preview, log_level)
}

pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result<ExitStatus> {
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ changelog_sections.breaking = "Breaking changes"
changelog_sections.preview = "Preview features"
changelog_sections.rule = "Rule changes"
changelog_sections.formatter = "Formatter"
changelog_sections.server = "Server"
changelog_sections.cli = "CLI"
changelog_sections.configuration = "Configuration"
changelog_sections.bug = "Bug fixes"
Expand Down

0 comments on commit e832327

Please sign in to comment.