diff --git a/Cargo.lock b/Cargo.lock index 7ee2ff7..bc609d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -282,6 +282,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb745187d7f4d76267b37485a65e0149edd0e91a4cfcdd3f27524ad86cee9f3" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.4.7" @@ -402,6 +411,7 @@ dependencies = [ "ascii_table", "chrono", "clap", + "clap_complete", "emfcamp-schedule-api", "termcolor", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 1754574..3734732 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ axum = { version = "0.7.5", features = ["macros"] } axum-extra = { version = "0.9.3", features = ["query"] } chrono = { version = "0.4.38", features = ["serde"] } clap = { version = "~4.4.0", features = ["derive", "env"] } +clap_complete = "~4.4.10" emfcamp-schedule-api = { path = "./client/" } reqwest = { version = "0.11.27", default-features = false, features = ["json", "rustls-tls"] } serde = { version = "1.0.198", features = ["derive"] } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 6f5ac64..bff15fa 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -8,6 +8,7 @@ edition.workspace = true ascii_table.workspace = true chrono.workspace = true clap.workspace = true +clap_complete.workspace = true emfcamp-schedule-api.workspace = true termcolor.workspace = true tokio.workspace = true diff --git a/cli/src/main.rs b/cli/src/main.rs index df82720..685d10e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,8 @@ mod commands; mod formatting; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, Parser, Subcommand}; +use clap_complete::Shell; use url::Url; #[derive(Debug, Parser)] @@ -25,7 +26,7 @@ enum Command { /// Show the complete schedule Full(commands::full::FullOptions), - /// Show the complete scheule minus events from the past + /// Show the complete schedule minus events from the past Upcoming(commands::upcoming::UpcomingOptions), /// Show the EPG style now and next for venue(s) @@ -36,6 +37,12 @@ enum Command { /// List all venues Venues, + + /// Generate shell completions + ShellCompletions { + /// The shell to generate completions for + shell: Shell, + }, } #[tokio::main] @@ -52,5 +59,12 @@ async fn main() { Command::NowNext(args) => commands::now_next::run(args, schedule), Command::Details(args) => commands::details::run(args, schedule), Command::Venues => commands::venues::run(schedule), + Command::ShellCompletions { shell } => print_shell_completions(shell), } } + +fn print_shell_completions(shell: Shell) { + let mut cmd = Cli::command(); + let name = cmd.get_name().to_string(); + clap_complete::generate(shell, &mut cmd, name, &mut std::io::stdout()); +}