mirror of
https://github.com/nushell/nushell.git
synced 2025-05-02 09:04:30 +02:00
A bit of tidying
This commit is contained in:
parent
d5704808d4
commit
78bb5647fc
@ -55,8 +55,6 @@ pub fn plugin_inc(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let request_raw = serde_json::to_string(&request).unwrap();
|
let request_raw = serde_json::to_string(&request).unwrap();
|
||||||
stdin.write(format!("{}\n", request_raw).as_bytes());
|
stdin.write(format!("{}\n", request_raw).as_bytes());
|
||||||
|
|
||||||
// println!("Wrote out init");
|
|
||||||
// println!("{:?}", v);
|
|
||||||
let request = JsonRpc::new("filter", v);
|
let request = JsonRpc::new("filter", v);
|
||||||
let request_raw = serde_json::to_string(&request).unwrap();
|
let request_raw = serde_json::to_string(&request).unwrap();
|
||||||
stdin.write(format!("{}\n", request_raw).as_bytes());
|
stdin.write(format!("{}\n", request_raw).as_bytes());
|
||||||
|
@ -9,10 +9,10 @@ use std::io;
|
|||||||
pub struct JsonRpc<T> {
|
pub struct JsonRpc<T> {
|
||||||
jsonrpc: String,
|
jsonrpc: String,
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub params: T,
|
pub params: Vec<T>,
|
||||||
}
|
}
|
||||||
impl<T> JsonRpc<T> {
|
impl<T> JsonRpc<T> {
|
||||||
pub fn new<U: Into<String>>(method: U, params: T) -> Self {
|
pub fn new<U: Into<String>>(method: U, params: Vec<T>) -> Self {
|
||||||
JsonRpc {
|
JsonRpc {
|
||||||
jsonrpc: "2.0".into(),
|
jsonrpc: "2.0".into(),
|
||||||
method: method.into(),
|
method: method.into(),
|
||||||
@ -21,12 +21,11 @@ impl<T> JsonRpc<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_response<T: Serialize>(result: T) {
|
fn send_response<T: Serialize>(result: Vec<T>) {
|
||||||
let response = JsonRpc::new("response", result);
|
let response = JsonRpc::new("response", result);
|
||||||
let response_raw = serde_json::to_string(&response).unwrap();
|
let response_raw = serde_json::to_string(&response).unwrap();
|
||||||
println!("{}", response_raw);
|
println!("{}", response_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(tag = "method")]
|
#[serde(tag = "method")]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
@ -56,9 +55,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
inc_by = i;
|
inc_by = i;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
send_response(ReturnValue::Value(Value::Error(Box::new(
|
send_response(vec![ReturnValue::Value(Value::Error(
|
||||||
ShellError::string("Unrecognized type in params"),
|
Box::new(ShellError::string("Unrecognized type in params")),
|
||||||
))));
|
))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,25 +72,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
))]);
|
))]);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
send_response(ReturnValue::Value(Value::Error(Box::new(
|
send_response(vec![ReturnValue::Value(Value::Error(Box::new(
|
||||||
ShellError::string("Unrecognized type in stream"),
|
ShellError::string("Unrecognized type in stream"),
|
||||||
))));
|
)))]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(NuCommand::quit) => {
|
Ok(NuCommand::quit) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
send_response(ReturnValue::Value(Value::Error(Box::new(
|
send_response(vec![ReturnValue::Value(Value::Error(Box::new(
|
||||||
ShellError::string("Unrecognized type in stream"),
|
ShellError::string("Unrecognized type in stream"),
|
||||||
))));
|
)))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(_) => {
|
||||||
send_response(ReturnValue::Value(Value::Error(Box::new(
|
send_response(vec![ReturnValue::Value(Value::Error(Box::new(
|
||||||
ShellError::string("Unrecognized type in stream"),
|
ShellError::string("Unrecognized type in stream"),
|
||||||
))));
|
)))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user