mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
feat: add shell completions
Auto-generated with clap.
This commit is contained in:
parent
df55cdfa9f
commit
4381fd505d
6 changed files with 100 additions and 3 deletions
53
build.rs
Normal file
53
build.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Importing from Ironbar modules brings in lots of things not used by the build script
|
||||
// we can just globally suppress those.
|
||||
#![allow(unused, dead_code)]
|
||||
|
||||
#[path = "src/cli.rs"]
|
||||
mod cli;
|
||||
|
||||
#[path = "src/error.rs"]
|
||||
mod error;
|
||||
|
||||
#[path = "src/ipc"]
|
||||
mod ipc {
|
||||
#[path = "commands.rs"]
|
||||
mod commands;
|
||||
|
||||
#[path = "responses.rs"]
|
||||
mod responses;
|
||||
|
||||
pub use commands::Command;
|
||||
pub use responses::Response;
|
||||
}
|
||||
|
||||
use clap::Command;
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::generate_to;
|
||||
use clap_complete::Shell::{Bash, Fish, Zsh};
|
||||
use cli::Args;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const NAME: &str = "ironbar";
|
||||
|
||||
fn generate_shell_completions(mut cmd: Command) -> std::io::Result<()> {
|
||||
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||
let comp_dir = PathBuf::from(MANIFEST_DIR).join("target/completions");
|
||||
|
||||
fs::create_dir_all(&comp_dir)?;
|
||||
|
||||
for shell in [Bash, Fish, Zsh] {
|
||||
generate_to(shell, &mut cmd, NAME, &comp_dir)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let mut cmd = Args::command();
|
||||
cmd.set_bin_name(NAME);
|
||||
|
||||
generate_shell_completions(cmd)?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue