Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove error messages for removed CLI aliases #12833

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 3 additions & 46 deletions crates/ruff/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::io::Write;
use std::process::ExitCode;

use clap::{Parser, Subcommand};
use clap::Parser;
use colored::Colorize;
use log::error;
use std::io::Write;

use ruff::args::{Args, Command};
use ruff::args::Args;
use ruff::{run, ExitStatus};
use ruff_linter::logging::{set_up_logging, LogLevel};

#[cfg(target_os = "windows")]
#[global_allocator]
Expand Down Expand Up @@ -41,47 +39,6 @@ pub fn main() -> ExitCode {
let args = wild::args_os();
let args = argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap();

// We can't use `warn_user` here because logging isn't set up at this point
// and we also don't know if the user runs ruff with quiet.
// Keep the message and pass it to `run` that is responsible for emitting the warning.
let deprecated_alias_error = match args.get(1).and_then(|arg| arg.to_str()) {
// Deprecated aliases that are handled by clap
Some("--explain") => {
Some("`ruff --explain <RULE>` has been removed. Use `ruff rule <RULE>` instead.")
}
Some("--clean") => {
Some("`ruff --clean` has been removed. Use `ruff clean` instead.")
}
Some("--generate-shell-completion") => {
Some("`ruff --generate-shell-completion <SHELL>` has been removed. Use `ruff generate-shell-completion <SHELL>` instead.")
}
// Deprecated `ruff` alias to `ruff check`
// Clap doesn't support default subcommands but we want to run `check` by
// default for convenience and backwards-compatibility, so we just
// preprocess the arguments accordingly before passing them to Clap.
Some(arg) if !Command::has_subcommand(arg)
&& arg != "-h"
&& arg != "--help"
&& arg != "-V"
&& arg != "--version"
&& arg != "help" => {
{
Some("`ruff <path>` has been removed. Use `ruff check <path>` instead.")
}
},
_ => None
};

if let Some(error) = deprecated_alias_error {
#[allow(clippy::print_stderr)]
if set_up_logging(LogLevel::Default).is_ok() {
error!("{}", error);
} else {
eprintln!("{}", error.red().bold());
}
return ExitCode::FAILURE;
}

let args = Args::parse_from(args);

match run(args) {
Expand Down
Loading