Skip to content

Commit

Permalink
Add shell completions to schedule CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Apr 27, 2024
1 parent faf4596 commit b6c3b70
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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)
Expand All @@ -36,6 +37,12 @@ enum Command {

/// List all venues
Venues,

/// Generate shell completions
ShellCompletions {
/// The shell to generate completions for
shell: Shell,
},
}

#[tokio::main]
Expand All @@ -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());
}

0 comments on commit b6c3b70

Please sign in to comment.