nix: add clap completions
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -201,6 +201,15 @@ dependencies = [
|
||||
"terminal_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.5.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "430b4dc2b5e3861848de79627b2bedc9f3342c7da5173a14eaa5d0f8dc18ae5d"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.49"
|
||||
@@ -815,6 +824,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"futures-util",
|
||||
"nix",
|
||||
"sd-notify",
|
||||
|
||||
@@ -30,6 +30,7 @@ sd-notify = "0.4.5"
|
||||
serde_json = "1.0.148"
|
||||
uucore = { version = "0.5.0", features = ["utmpx"] }
|
||||
zlink = { version = "0.2.0", features = ["introspection"] }
|
||||
clap_complete = "4.5.65"
|
||||
|
||||
[lib]
|
||||
name = "roowho2_lib"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
lib
|
||||
, rustPlatform
|
||||
, stdenv
|
||||
, buildPackages
|
||||
, installShellFiles
|
||||
, versionCheckHook
|
||||
|
||||
@@ -20,6 +21,21 @@ rustPlatform.buildRustPackage {
|
||||
|
||||
RUSTFLAGS = "-Zhigher-ranked-assumptions";
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
postInstall = let
|
||||
emulator = stdenv.hostPlatform.emulator buildPackages;
|
||||
installShellCompletions = lib.mapCartesianProduct ({ shell, command }: ''
|
||||
(
|
||||
export PATH="$out/bin:$PATH"
|
||||
"${emulator}" "${command}" --completions=${shell} > "$TMP/${command}.${shell}"
|
||||
)
|
||||
installShellCompletion "--${shell}" --cmd "${command}" "$TMP/${command}.${shell}"
|
||||
'') {
|
||||
shell = [ "bash" "zsh" "fish" ];
|
||||
command = [ "rwho" "ruptime" ];
|
||||
};
|
||||
in lib.concatStringsSep "\n" installShellCompletions;
|
||||
|
||||
meta = with lib; {
|
||||
license = licenses.mit;
|
||||
platforms = platforms.linux ++ platforms.darwin;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Context;
|
||||
use chrono::{Duration, Utc};
|
||||
use clap::Parser;
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap_complete::{Shell, generate};
|
||||
|
||||
use roowho2_lib::{proto::WhodStatusUpdate, server::varlink_api::RwhodClientProxy};
|
||||
|
||||
@@ -44,12 +45,27 @@ pub struct Args {
|
||||
/// Output in JSON format
|
||||
#[arg(long, short)]
|
||||
json: bool,
|
||||
|
||||
/// Generate shell completion scripts for the specified shell
|
||||
/// and print them to stdout.
|
||||
#[arg(long, value_enum, hide = true)]
|
||||
completions: Option<Shell>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
if let Some(shell) = args.completions {
|
||||
generate(
|
||||
shell,
|
||||
&mut Args::command(),
|
||||
"ruptime",
|
||||
&mut std::io::stdout(),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut conn = zlink::unix::connect("/run/roowho2/roowho2.varlink")
|
||||
.await
|
||||
.expect("Failed to connect to rwhod server");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap_complete::{Shell, generate};
|
||||
use roowho2_lib::{proto::WhodUserEntry, server::varlink_api::RwhodClientProxy};
|
||||
|
||||
/// Check who is logged in on local machines.
|
||||
@@ -29,12 +30,22 @@ pub struct Args {
|
||||
/// Output in JSON format
|
||||
#[arg(long, short)]
|
||||
json: bool,
|
||||
|
||||
/// Generate shell completion scripts for the specified shell
|
||||
/// and print them to stdout.
|
||||
#[arg(long, value_enum, hide = true)]
|
||||
completions: Option<Shell>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
if let Some(shell) = args.completions {
|
||||
generate(shell, &mut Args::command(), "rwho", &mut std::io::stdout());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut conn = zlink::unix::connect("/run/roowho2/roowho2.varlink")
|
||||
.await
|
||||
.expect("Failed to connect to rwhod server");
|
||||
|
||||
Reference in New Issue
Block a user