nix: add clap completions
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -201,6 +201,15 @@ dependencies = [
|
|||||||
"terminal_size",
|
"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]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.49"
|
version = "4.5.49"
|
||||||
@@ -815,6 +824,7 @@ dependencies = [
|
|||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"nix",
|
"nix",
|
||||||
"sd-notify",
|
"sd-notify",
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ sd-notify = "0.4.5"
|
|||||||
serde_json = "1.0.148"
|
serde_json = "1.0.148"
|
||||||
uucore = { version = "0.5.0", features = ["utmpx"] }
|
uucore = { version = "0.5.0", features = ["utmpx"] }
|
||||||
zlink = { version = "0.2.0", features = ["introspection"] }
|
zlink = { version = "0.2.0", features = ["introspection"] }
|
||||||
|
clap_complete = "4.5.65"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "roowho2_lib"
|
name = "roowho2_lib"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
lib
|
lib
|
||||||
, rustPlatform
|
, rustPlatform
|
||||||
, stdenv
|
, stdenv
|
||||||
|
, buildPackages
|
||||||
, installShellFiles
|
, installShellFiles
|
||||||
, versionCheckHook
|
, versionCheckHook
|
||||||
|
|
||||||
@@ -20,6 +21,21 @@ rustPlatform.buildRustPackage {
|
|||||||
|
|
||||||
RUSTFLAGS = "-Zhigher-ranked-assumptions";
|
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; {
|
meta = with lib; {
|
||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
platforms = platforms.linux ++ platforms.darwin;
|
platforms = platforms.linux ++ platforms.darwin;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use chrono::{Duration, Utc};
|
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};
|
use roowho2_lib::{proto::WhodStatusUpdate, server::varlink_api::RwhodClientProxy};
|
||||||
|
|
||||||
@@ -44,12 +45,27 @@ pub struct Args {
|
|||||||
/// Output in JSON format
|
/// Output in JSON format
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
json: bool,
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
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")
|
let mut conn = zlink::unix::connect("/run/roowho2/roowho2.varlink")
|
||||||
.await
|
.await
|
||||||
.expect("Failed to connect to rwhod server");
|
.expect("Failed to connect to rwhod server");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::Parser;
|
use clap::{CommandFactory, Parser};
|
||||||
|
use clap_complete::{Shell, generate};
|
||||||
use roowho2_lib::{proto::WhodUserEntry, server::varlink_api::RwhodClientProxy};
|
use roowho2_lib::{proto::WhodUserEntry, server::varlink_api::RwhodClientProxy};
|
||||||
|
|
||||||
/// Check who is logged in on local machines.
|
/// Check who is logged in on local machines.
|
||||||
@@ -29,12 +30,27 @@ pub struct Args {
|
|||||||
/// Output in JSON format
|
/// Output in JSON format
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
json: bool,
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
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")
|
let mut conn = zlink::unix::connect("/run/roowho2/roowho2.varlink")
|
||||||
.await
|
.await
|
||||||
.expect("Failed to connect to rwhod server");
|
.expect("Failed to connect to rwhod server");
|
||||||
|
|||||||
Reference in New Issue
Block a user