Nushell plugin for interacting with D-Bus
1use nu_plugin::{MsgPackSerializer, Plugin, PluginCommand, serve_plugin};
2use nu_protocol::SyntaxShape;
3
4mod client;
5mod commands;
6mod config;
7mod convert;
8mod dbus_type;
9mod introspection;
10mod pattern;
11
12fn main() {
13 serve_plugin(&NuPluginDbus, MsgPackSerializer)
14}
15
16/// The main plugin interface for nushell
17pub struct NuPluginDbus;
18
19impl Plugin for NuPluginDbus {
20 fn version(&self) -> String {
21 env!("CARGO_PKG_VERSION").into()
22 }
23
24 fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
25 vec![
26 Box::new(commands::Main),
27 Box::new(commands::Introspect),
28 Box::new(commands::Call),
29 Box::new(commands::Get),
30 Box::new(commands::GetAll),
31 Box::new(commands::Set),
32 Box::new(commands::List),
33 ]
34 }
35}
36
37/// For conveniently adding the base options to a dbus command
38trait DbusSignatureUtilExt {
39 fn dbus_command(self) -> Self;
40 fn accepts_dbus_client_options(self) -> Self;
41 fn accepts_timeout(self) -> Self;
42}
43
44impl DbusSignatureUtilExt for nu_protocol::Signature {
45 fn dbus_command(self) -> Self {
46 self.category(nu_protocol::Category::Platform)
47 }
48
49 fn accepts_dbus_client_options(self) -> Self {
50 self.switch("session", "Send to the session message bus (default)", None)
51 .switch("system", "Send to the system message bus", None)
52 .switch(
53 "started",
54 "Send to the bus that started this process, if applicable",
55 None,
56 )
57 .named(
58 "bus",
59 SyntaxShape::String,
60 "Send to the bus server at the given address",
61 None,
62 )
63 .named(
64 "peer",
65 SyntaxShape::String,
66 "Send to a non-bus D-Bus server at the given address. \
67 Will not call the Hello method on initialization.",
68 None,
69 )
70 }
71
72 fn accepts_timeout(self) -> Self {
73 self.named(
74 "timeout",
75 SyntaxShape::Duration,
76 "How long to wait for a response",
77 None,
78 )
79 }
80}