mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 10:38:57 +00:00
Add CLI autocompletion using clap_complete (#2559)
This commit is contained in:
10
sqlx-cli/src/completions.rs
Normal file
10
sqlx-cli/src/completions.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use std::io;
|
||||
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{generate, Shell};
|
||||
|
||||
use crate::opt::Command;
|
||||
|
||||
pub fn run(shell: Shell) {
|
||||
generate(shell, &mut Command::command(), "sqlx", &mut io::stdout())
|
||||
}
|
||||
@@ -12,6 +12,8 @@ mod database;
|
||||
mod metadata;
|
||||
// mod migration;
|
||||
// mod migrator;
|
||||
#[cfg(feature = "completions")]
|
||||
mod completions;
|
||||
mod migrate;
|
||||
mod opt;
|
||||
mod prepare;
|
||||
@@ -68,6 +70,9 @@ pub async fn run(opt: Opt) -> Result<()> {
|
||||
connect_opts,
|
||||
args,
|
||||
} => prepare::run(check, workspace, connect_opts, args).await?,
|
||||
|
||||
#[cfg(feature = "completions")]
|
||||
Command::Completions { shell } => completions::run(shell),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::ops::{Deref, Not};
|
||||
|
||||
use clap::{Args, Parser};
|
||||
#[cfg(feature = "completions")]
|
||||
use clap_complete::Shell;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version, about, author)]
|
||||
@@ -46,6 +48,10 @@ pub enum Command {
|
||||
|
||||
#[clap(alias = "mig")]
|
||||
Migrate(MigrateOpt),
|
||||
|
||||
#[cfg(feature = "completions")]
|
||||
/// Generate shell completions for the specified shell
|
||||
Completions { shell: Shell },
|
||||
}
|
||||
|
||||
/// Group of commands for creating and dropping your database.
|
||||
|
||||
Reference in New Issue
Block a user