nix: add clap completions
All checks were successful
Build and test / check (push) Successful in 59s
Build and test / build (push) Successful in 1m37s
Build and test / test (push) Successful in 3m3s
Build and test / docs (push) Successful in 2m52s

This commit is contained in:
2026-01-09 05:16:12 +09:00
parent 6c3a9e9e12
commit dd23346bda
5 changed files with 56 additions and 2 deletions

View File

@@ -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");

View File

@@ -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");