Skip to content

Commit 7fcb4a4

Browse files
committed
set up nushell plugin
1 parent 0461ce1 commit 7fcb4a4

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Cargo.lock
1212

1313
# MSVC Windows builds of rustc generate these, which store debugging information
1414
*.pdb
15+
16+
17+
# Added by cargo
18+
19+
/target

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "nu_plugin_dbus"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
nu-plugin = "0.89.0"
10+
nu-protocol = { version = "0.89.0", features = ["plugin"] }

src/main.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use nu_plugin::{serve_plugin, MsgPackSerializer, Plugin, EvaluatedCall, LabeledError};
2+
use nu_protocol::{PluginSignature, Value};
3+
4+
fn main() {
5+
serve_plugin(&mut NuPluginDbus, MsgPackSerializer)
6+
}
7+
8+
struct NuPluginDbus;
9+
10+
impl Plugin for NuPluginDbus {
11+
fn signature(&self) -> Vec<PluginSignature> {
12+
vec![
13+
PluginSignature::build("dbus")
14+
.usage("Commands for interacting with D-Bus")
15+
.search_terms(vec!["dbus".into()])
16+
.category(nu_protocol::Category::Platform),
17+
]
18+
}
19+
20+
fn run(
21+
&mut self,
22+
name: &str,
23+
call: &EvaluatedCall,
24+
input: &Value,
25+
) -> Result<Value, LabeledError> {
26+
match name {
27+
"dbus" => Err(LabeledError {
28+
label: "The `dbus` command requires a subcommand".into(),
29+
msg: "add --help to see subcommands".into(),
30+
span: Some(call.head)
31+
}),
32+
33+
_ => Err(LabeledError {
34+
label: "Plugin invoked with unknown command name".into(),
35+
msg: "unknown command".into(),
36+
span: Some(call.head)
37+
})
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)