···6060 result: None
6161 },
6262 PluginExample {
6363- example: "dbus call --dest=org.mpris.MediaPlayer2.spotify \
6464- /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties Get \
6363+ example: "dbus call --dest=org.freedesktop.Notifications \
6464+ /org/freedesktop/Notifications org.freedesktop.Notifications \
6565+ Notify \"Floppy disks\" 0 \"media-floppy\" \"Rarely seen\" \
6666+ \"But sometimes still used\" [] {} 5000".into(),
6767+ description: "Show a notification on the desktop for 5 seconds".into(),
6868+ result: None
6969+ },
7070+ ]),
7171+ PluginSignature::build("dbus get")
7272+ .is_dbus_command()
7373+ .accepts_dbus_client_options()
7474+ .usage("Get a D-Bus property")
7575+ .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
7676+ .required_named("dest", SyntaxShape::String,
7777+ "The name of the connection to read the property from",
7878+ None)
7979+ .required("object", SyntaxShape::String,
8080+ "The path to the object to read the property from")
8181+ .required("interface", SyntaxShape::String,
8282+ "The name of the interface the property belongs to")
8383+ .required("property", SyntaxShape::String,
8484+ "The name of the property to read")
8585+ .plugin_examples(vec![
8686+ PluginExample {
8787+ example: "dbus get --dest=org.mpris.MediaPlayer2.spotify \
8888+ /org/mpris/MediaPlayer2 \
6589 org.mpris.MediaPlayer2.Player Metadata".into(),
6690 description: "Get the currently playing song in Spotify".into(),
6791 result: Some(Value::record(nu_protocol::record!(
···7397 "xesam:url" => str!("https://open.spotify.com/track/51748BvzeeMs4PIdPuyZmv"),
7498 ), Span::unknown()))
7599 },
100100+ ]),
101101+ PluginSignature::build("dbus get-all")
102102+ .is_dbus_command()
103103+ .accepts_dbus_client_options()
104104+ .usage("Get all D-Bus property for the given objects")
105105+ .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
106106+ .required_named("dest", SyntaxShape::String,
107107+ "The name of the connection to read the property from",
108108+ None)
109109+ .required("object", SyntaxShape::String,
110110+ "The path to the object to read the property from")
111111+ .required("interface", SyntaxShape::String,
112112+ "The name of the interface the property belongs to")
113113+ .plugin_examples(vec![
76114 PluginExample {
7777- example: "dbus call --dest=org.freedesktop.Notifications \
7878- /org/freedesktop/Notifications org.freedesktop.Notifications \
7979- Notify \"Floppy disks\" 0 \"media-floppy\" \"Rarely seen\" \
8080- \"But sometimes still used\" [] {} 5000".into(),
8181- description: "Show a notification on the desktop for 5 seconds".into(),
8282- result: None
115115+ example: "dbus get-all --dest=org.mpris.MediaPlayer2.spotify \
116116+ /org/mpris/MediaPlayer2 \
117117+ org.mpris.MediaPlayer2.Player".into(),
118118+ description: "Get the current player state of Spotify".into(),
119119+ result: Some(Value::record(nu_protocol::record!(
120120+ "CanPlay" => Value::bool(true, Span::unknown()),
121121+ "Volume" => Value::float(0.43, Span::unknown()),
122122+ "PlaybackStatus" => str!("Paused"),
123123+ ), Span::unknown()))
124124+ },
125125+ ]),
126126+ PluginSignature::build("dbus set")
127127+ .is_dbus_command()
128128+ .accepts_dbus_client_options()
129129+ .usage("Get all D-Bus property for the given objects")
130130+ .named("timeout", SyntaxShape::Duration, "How long to wait for a response", None)
131131+ .named("signature", SyntaxShape::String,
132132+ "Signature of the value to set, in D-Bus format.\n \
133133+ If not provided, it will be determined from introspection.\n \
134134+ If --no-introspect is specified and this is not provided, it will \
135135+ be guessed (poorly)", None)
136136+ .required_named("dest", SyntaxShape::String,
137137+ "The name of the connection to write the property on",
138138+ None)
139139+ .required("object", SyntaxShape::String,
140140+ "The path to the object to write the property on")
141141+ .required("interface", SyntaxShape::String,
142142+ "The name of the interface the property belongs to")
143143+ .required("property", SyntaxShape::String,
144144+ "The name of the property to write")
145145+ .required("value", SyntaxShape::Any,
146146+ "The value to write to the property")
147147+ .plugin_examples(vec![
148148+ PluginExample {
149149+ example: "dbus set --dest=org.mpris.MediaPlayer2.spotify \
150150+ /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player \
151151+ Volume 0.5".into(),
152152+ description: "Set the volume of Spotify to 50%".into(),
153153+ result: None,
83154 },
84155 ]),
85156 ]
···99170 }),
100171101172 "dbus call" => self.call(call),
173173+ "dbus get" => self.get(call),
174174+ "dbus get-all" => self.get_all(call),
175175+ "dbus set" => self.set(call),
102176103177 _ => Err(LabeledError {
104178 label: "Plugin invoked with unknown command name".into(),
···155229 1 if flatten => Ok(values.into_iter().nth(0).unwrap()),
156230 _ => Ok(Value::list(values, Span::unknown()))
157231 }
232232+ }
233233+234234+ fn get(&self, call: &EvaluatedCall) -> Result<Value, LabeledError> {
235235+ let config = DbusClientConfig::try_from(call)?;
236236+ let dbus = DbusClient::new(config)?;
237237+ dbus.get(
238238+ &call.get_flag("dest")?.unwrap(),
239239+ &call.req(0)?,
240240+ &call.req(1)?,
241241+ &call.req(2)?,
242242+ )
243243+ }
244244+245245+ fn get_all(&self, call: &EvaluatedCall) -> Result<Value, LabeledError> {
246246+ let config = DbusClientConfig::try_from(call)?;
247247+ let dbus = DbusClient::new(config)?;
248248+ dbus.get_all(
249249+ &call.get_flag("dest")?.unwrap(),
250250+ &call.req(0)?,
251251+ &call.req(1)?,
252252+ )
253253+ }
254254+255255+ fn set(&self, call: &EvaluatedCall) -> Result<Value, LabeledError> {
256256+ let config = DbusClientConfig::try_from(call)?;
257257+ let dbus = DbusClient::new(config)?;
258258+ dbus.set(
259259+ &call.get_flag("dest")?.unwrap(),
260260+ &call.req(0)?,
261261+ &call.req(1)?,
262262+ &call.req(2)?,
263263+ call.get_flag("signature")?.as_ref(),
264264+ &call.req(3)?,
265265+ )?;
266266+ Ok(Value::nothing(Span::unknown()))
158267 }
159268}