Require --preview for `ruff server` (#10368)

## 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.
This commit is contained in:
Jane Lewis 2024-03-13 16:52:44 -07:00 committed by GitHub
parent 324390607c
commit e832327a56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 4 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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> {

View File

@ -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"