Add CLI autocompletion using clap_complete (#2559)

This commit is contained in:
Jon Heinritz
2023-06-30 23:59:35 +02:00
committed by GitHub
parent 4b254ea1cb
commit 1b7631eddc
5 changed files with 35 additions and 1 deletions

View 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())
}

View File

@@ -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(())

View File

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