mirror of https://github.com/astral-sh/ruff
[ty] Support `generate-shell-completion` (#17879)
## Summary Resolves #15502. `ty generate-shell-completion` now works in a similar manner to `ruff generate-shell-completion`. ## Test Plan Manually: <details> ```shell $ cargo run --package ty generate-shell-completion nushell module completions { # An extremely fast Python type checker. export extern ty [ --help(-h) # Print help --version(-V) # Print version ] # ... } export use completions * ``` </details>
This commit is contained in:
parent
443f62e98d
commit
a33d0d4bf4
|
|
@ -3955,6 +3955,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"argfile",
|
"argfile",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete_command",
|
||||||
"colored 3.0.0",
|
"colored 3.0.0",
|
||||||
"countme",
|
"countme",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ ty_server = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
argfile = { workspace = true }
|
argfile = { workspace = true }
|
||||||
clap = { workspace = true, features = ["wrap_help", "string"] }
|
clap = { workspace = true, features = ["wrap_help", "string"] }
|
||||||
|
clap_complete_command = { workspace = true }
|
||||||
colored = { workspace = true }
|
colored = { workspace = true }
|
||||||
countme = { workspace = true, features = ["enable"] }
|
countme = { workspace = true, features = ["enable"] }
|
||||||
crossbeam = { workspace = true }
|
crossbeam = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ pub(crate) enum Command {
|
||||||
|
|
||||||
/// Display ty's version
|
/// Display ty's version
|
||||||
Version,
|
Version,
|
||||||
|
|
||||||
|
/// Generate shell completion
|
||||||
|
#[clap(hide = true)]
|
||||||
|
GenerateShellCompletion { shell: clap_complete_command::Shell },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use std::sync::Mutex;
|
||||||
use crate::args::{Args, CheckCommand, Command, TerminalColor};
|
use crate::args::{Args, CheckCommand, Command, TerminalColor};
|
||||||
use crate::logging::setup_tracing;
|
use crate::logging::setup_tracing;
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use clap::Parser;
|
use clap::{CommandFactory, Parser};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use crossbeam::channel as crossbeam_channel;
|
use crossbeam::channel as crossbeam_channel;
|
||||||
use rayon::ThreadPoolBuilder;
|
use rayon::ThreadPoolBuilder;
|
||||||
|
|
@ -68,6 +68,10 @@ fn run() -> anyhow::Result<ExitStatus> {
|
||||||
Command::Server => run_server().map(|()| ExitStatus::Success),
|
Command::Server => run_server().map(|()| ExitStatus::Success),
|
||||||
Command::Check(check_args) => run_check(check_args),
|
Command::Check(check_args) => run_check(check_args),
|
||||||
Command::Version => version().map(|()| ExitStatus::Success),
|
Command::Version => version().map(|()| ExitStatus::Success),
|
||||||
|
Command::GenerateShellCompletion { shell } => {
|
||||||
|
shell.generate(&mut Args::command(), &mut stdout());
|
||||||
|
Ok(ExitStatus::Success)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue