···2020 dbus get - Get a D-Bus property
2121 dbus get-all - Get all D-Bus property for the given objects
2222 dbus introspect - Introspect a D-Bus object
2323+ dbus list - List all available connection names on the bus
2324 dbus set - Get all D-Bus property for the given objects
24252526 Flags:
···196197 Set the volume of Spotify to 50%
197198 > dbus set --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Volume 0.5
198199200200+## `dbus list`
201201+202202+ List all available connection names on the bus
203203+204204+ These can be used as arguments for --dest on any of the other commands.
205205+206206+ Search terms: dbus
207207+208208+ Usage:
209209+ > dbus list {flags} (pattern)
210210+211211+ Flags:
212212+ -h, --help - Display the help message for this command
213213+ --session - Send to the session message bus (default)
214214+ --system - Send to the system message bus
215215+ --started - Send to the bus that started this process, if applicable
216216+ --bus <String> - Send to the bus server at the given address
217217+ --peer <String> - Send to a non-bus D-Bus server at the given address. Will not call the Hello method on initialization.
218218+ --timeout <Duration> - How long to wait for a response
219219+220220+ Parameters:
221221+ pattern <string>: An optional glob-like pattern to filter the result by (optional)
222222+223223+ Examples:
224224+ List all names available on the bus
225225+ > dbus list
226226+227227+ List top-level freedesktop.org names on the bus (e.g. matches `org.freedesktop.PowerManagement`, but not `org.freedesktop.Management.Inhibit`)
228228+ > dbus list org.freedesktop.*
229229+ ╭───┬───────────────────────────────╮
230230+ │ 0 │ org.freedesktop.DBus │
231231+ │ 1 │ org.freedesktop.Flatpak │
232232+ │ 2 │ org.freedesktop.Notifications │
233233+ ╰───┴───────────────────────────────╯
234234+235235+ List all MPRIS2 media players on the bus
236236+ > dbus list org.mpris.MediaPlayer2.**
237237+ ╭───┬────────────────────────────────────────────────╮
238238+ │ 0 │ org.mpris.MediaPlayer2.spotify │
239239+ │ 1 │ org.mpris.MediaPlayer2.kdeconnect.mpris_000001 │
240240+ ╰───┴────────────────────────────────────────────────╯
···66mod convert;
77mod dbus_type;
88mod introspection;
99+mod pattern;
9101011use config::*;
1112use client::*;
1313+1414+use crate::pattern::Pattern;
12151316fn main() {
1417 serve_plugin(&mut NuPluginDbus, MsgPackSerializer)
···2932 PluginSignature::build("dbus introspect")
3033 .is_dbus_command()
3134 .accepts_dbus_client_options()
3535+ .accepts_timeout()
3236 .usage("Introspect a D-Bus object")
3337 .extra_usage("Returns information about available nodes, interfaces, methods, \
3438 signals, and properties on the given object path")
3535- .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
3639 .required_named("dest", SyntaxShape::String,
3740 "The name of the connection that owns the object",
3841 None)
···6366 PluginSignature::build("dbus call")
6467 .is_dbus_command()
6568 .accepts_dbus_client_options()
6969+ .accepts_timeout()
6670 .usage("Call a method and get its response")
6771 .extra_usage("Returns an array if the method call returns more than one value.")
6868- .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
6972 .named("signature", SyntaxShape::String,
7073 "Signature of the arguments to send, in D-Bus format.\n \
7174 If not provided, they will be determined from introspection.\n \
···105108 PluginSignature::build("dbus get")
106109 .is_dbus_command()
107110 .accepts_dbus_client_options()
111111+ .accepts_timeout()
108112 .usage("Get a D-Bus property")
109109- .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
110113 .required_named("dest", SyntaxShape::String,
111114 "The name of the connection to read the property from",
112115 None)
···135138 PluginSignature::build("dbus get-all")
136139 .is_dbus_command()
137140 .accepts_dbus_client_options()
141141+ .accepts_timeout()
138142 .usage("Get all D-Bus property for the given objects")
139139- .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
140143 .required_named("dest", SyntaxShape::String,
141144 "The name of the connection to read the property from",
142145 None)
···160163 PluginSignature::build("dbus set")
161164 .is_dbus_command()
162165 .accepts_dbus_client_options()
166166+ .accepts_timeout()
163167 .usage("Get all D-Bus property for the given objects")
164164- .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
165168 .named("signature", SyntaxShape::String,
166169 "Signature of the value to set, in D-Bus format.\n \
167170 If not provided, it will be determined from introspection.\n \
···187190 result: None,
188191 },
189192 ]),
193193+ PluginSignature::build("dbus list")
194194+ .is_dbus_command()
195195+ .accepts_dbus_client_options()
196196+ .accepts_timeout()
197197+ .usage("List all available connection names on the bus")
198198+ .extra_usage("These can be used as arguments for --dest on any of the other commands.")
199199+ .optional("pattern", SyntaxShape::String,
200200+ "An optional glob-like pattern to filter the result by")
201201+ .plugin_examples(vec![
202202+ PluginExample {
203203+ example: "dbus list".into(),
204204+ description: "List all names available on the bus".into(),
205205+ result: None,
206206+ },
207207+ PluginExample {
208208+ example: "dbus list org.freedesktop.*".into(),
209209+ description: "List top-level freedesktop.org names on the bus \
210210+ (e.g. matches `org.freedesktop.PowerManagement`, \
211211+ but not `org.freedesktop.Management.Inhibit`)".into(),
212212+ result: Some(Value::list(vec![
213213+ str!("org.freedesktop.DBus"),
214214+ str!("org.freedesktop.Flatpak"),
215215+ str!("org.freedesktop.Notifications"),
216216+ ], Span::unknown())),
217217+ },
218218+ PluginExample {
219219+ example: "dbus list org.mpris.MediaPlayer2.**".into(),
220220+ description: "List all MPRIS2 media players on the bus".into(),
221221+ result: Some(Value::list(vec![
222222+ str!("org.mpris.MediaPlayer2.spotify"),
223223+ str!("org.mpris.MediaPlayer2.kdeconnect.mpris_000001"),
224224+ ], Span::unknown())),
225225+ },
226226+ ])
190227 ]
191228 }
192229···208245 "dbus get" => self.get(call),
209246 "dbus get-all" => self.get_all(call),
210247 "dbus set" => self.set(call),
248248+ "dbus list" => self.list(call),
211249212250 _ => Err(LabeledError {
213251 label: "Plugin invoked with unknown command name".into(),
···222260trait DbusSignatureUtilExt {
223261 fn is_dbus_command(self) -> Self;
224262 fn accepts_dbus_client_options(self) -> Self;
263263+ fn accepts_timeout(self) -> Self;
225264}
226265227266impl DbusSignatureUtilExt for PluginSignature {
···239278 "Send to a non-bus D-Bus server at the given address. \
240279 Will not call the Hello method on initialization.",
241280 None)
281281+ }
282282+283283+ fn accepts_timeout(self) -> Self {
284284+ self.named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
242285 }
243286}
244287···309352 &call.req(3)?,
310353 )?;
311354 Ok(Value::nothing(call.head))
355355+ }
356356+357357+ fn list(&self, call: &EvaluatedCall) -> Result<Value, LabeledError> {
358358+ let config = DbusClientConfig::try_from(call)?;
359359+ let dbus = DbusClient::new(config)?;
360360+ let pattern = call.opt::<String>(0)?.map(|pat| Pattern::new(&pat, Some('.')));
361361+ let result = dbus.list(pattern.as_ref())?;
362362+ Ok(Value::list(
363363+ result.into_iter().map(|s| Value::string(s, call.head)).collect(),
364364+ call.head))
312365 }
313366}