mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
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:
Generated
+10
@@ -635,6 +635,15 @@ dependencies = [
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.5.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e3040c8291884ddf39445dc033c70abc2bc44a42f0a3a00571a0f483a83f0cd"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.28"
|
||||
@@ -2219,6 +2228,7 @@ dependencies = [
|
||||
"calloop 0.14.2",
|
||||
"calloop-wayland-source 0.4.0",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"directories",
|
||||
"drm-ffi",
|
||||
"fastrand",
|
||||
|
||||
@@ -59,6 +59,7 @@ bitflags.workspace = true
|
||||
bytemuck = { version = "1.22.0", features = ["derive"] }
|
||||
calloop = { version = "0.14.2", features = ["executor", "futures-io"] }
|
||||
clap = { workspace = true, features = ["string"] }
|
||||
clap_complete = "4.5.45"
|
||||
directories = "6.0.0"
|
||||
drm-ffi = "0.9.0"
|
||||
fastrand = "2.3.0"
|
||||
|
||||
@@ -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
@@ -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(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user