feat(cli): add completions cmd

Add a new "completions" command which takes a supported shell as an
argument. This command outputs a completions file to stdout, which can
be redirected to a file.
This commit is contained in:
LGUG2Z committed 2025-10-11 13:16:22 -07:00
1 parent 5c663d2cea
commit 6869805b82
5 files changed
+87 -57

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ edition = "2024"
komorebi-client = { path = "../komorebi-client", default-features = false }
clap = { workspace = true }
clap_complete = "4"
chrono = { workspace = true }
color-eyre = { workspace = true }
dirs = { workspace = true }
+12
View File
@@ -647,6 +647,12 @@ struct BorderOffset {
offset: i32,
}
#[derive(Parser)]
struct Completions {
#[clap(value_enum)]
shell: clap_complete::Shell,
}
#[derive(Parser)]
#[clap(author, about, version = build::CLAP_LONG_VERSION)]
struct Opts {
@@ -658,6 +664,8 @@ struct Opts {
enum SubCommand {
#[clap(hide = true)]
Docgen,
/// Generate komorebic CLI completions for the target shell
Completions(Completions),
/// Gather example configurations for a new-user quickstart
Quickstart,
/// Start komorebi as a background process
@@ -1220,6 +1228,10 @@ fn main() -> eyre::Result<()> {
}
}
}
SubCommand::Completions(arg) => {
let mut cli = Opts::command();
clap_complete::generate(arg.shell, &mut cli, "komorebic", &mut std::io::stdout());
}
SubCommand::Quickstart => {
fn write_file_with_prompt(
path: &PathBuf,