Add Shell completions (#1226)

* feat(cli): add subcommand to generate shell completions

* Update src/cli.rs

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>

---------

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
Jon Heinritz
2025-03-10 21:14:34 +01:00
committed by GitHub
parent b351f6ff22
commit 87b6c12625
4 changed files with 19 additions and 1 deletions
+3
View File
@@ -2,6 +2,7 @@ use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use clap_complete::Shell;
use niri_ipc::{Action, OutputAction};
use crate::utils::version;
@@ -54,6 +55,8 @@ pub enum Sub {
},
/// Cause a panic to check if the backtraces are good.
Panic,
/// Generate shell completions.
Completions { shell: Shell },
}
#[derive(Subcommand)]
+5 -1
View File
@@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, mem};
use clap::Parser;
use clap::{CommandFactory, Parser};
use directories::ProjectDirs;
use niri::cli::{Cli, Sub};
#[cfg(feature = "dbus")]
@@ -106,6 +106,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
return Ok(());
}
Sub::Panic => cause_panic(),
Sub::Completions { shell } => {
clap_complete::generate(shell, &mut Cli::command(), "niri", &mut io::stdout());
return Ok(());
}
}
}