Skip to content

Commit

Permalink
More CLI test tidy work
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jan 24, 2025
1 parent 9a6e2ca commit 26f7e46
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 168 deletions.
34 changes: 17 additions & 17 deletions crates/red_knot/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ pub(crate) struct Args {
#[derive(Debug, clap::Subcommand)]
pub(crate) enum Command {
/// Check a project for type errors.
Check(CheckArgs),
Check(CheckCommand),

/// Start the language server
Server,
}

#[derive(Debug, Parser)]
pub(crate) struct CheckArgs {
/// Run in watch mode by re-running whenever files change.
#[arg(long, short = 'W')]
pub(crate) watch: bool,
pub(crate) struct CheckCommand {
/// Run the command within the given project directory.
///
/// All `pyproject.toml` files will be discovered by walking up the directory tree from the given project directory,
/// as will the project's virtual environment (`.venv`) unless the `venv-path` option is set.
///
/// Other command-line arguments (such as relative paths) will be resolved relative to the current working directory.
#[arg(long, value_name = "PROJECT")]
pub(crate) project: Option<SystemPathBuf>,

/// Path to the virtual environment the project uses.
///
Expand All @@ -53,22 +58,17 @@ pub(crate) struct CheckArgs {
pub(crate) python_version: Option<PythonVersion>,

#[clap(flatten)]
pub(crate) rules: RulesArg,

/// Run the command within the given project directory.
///
/// All `pyproject.toml` files will be discovered by walking up the directory tree from the given project directory,
/// as will the project's virtual environment (`.venv`) unless the `venv-path` option is set.
///
/// Other command-line arguments (such as relative paths) will be resolved relative to the current working directory.
#[arg(long, value_name = "PROJECT")]
pub(crate) project: Option<SystemPathBuf>,
pub(crate) verbosity: Verbosity,

#[clap(flatten)]
pub(crate) verbosity: Verbosity,
pub(crate) rules: RulesArg,

/// Run in watch mode by re-running whenever files change.
#[arg(long, short = 'W')]
pub(crate) watch: bool,
}

impl CheckArgs {
impl CheckCommand {
pub(crate) fn into_options(self) -> Options {
let rules = if self.rules.is_empty() {
None
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::process::{ExitCode, Termination};
use std::sync::Mutex;

use crate::args::{Args, CheckArgs, Command};
use crate::args::{Args, CheckCommand, Command};
use crate::logging::setup_tracing;
use anyhow::{anyhow, Context};
use clap::Parser;
Expand Down Expand Up @@ -52,7 +52,7 @@ fn run() -> anyhow::Result<ExitStatus> {
}
}

fn run_check(args: CheckArgs) -> anyhow::Result<ExitStatus> {
fn run_check(args: CheckCommand) -> anyhow::Result<ExitStatus> {
let verbosity = args.verbosity.level();
countme::enable(verbosity.is_trace());
let _guard = setup_tracing(verbosity)?;
Expand Down
Loading

0 comments on commit 26f7e46

Please sign in to comment.