Nushell plugin for interacting with D-Bus
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

handle some remaining cases in output conversion, including u64

+13 -13
+1 -1
src/client.rs
··· 79 79 let resp = self.conn.send_with_reply_and_block(message, self.config.timeout.item) 80 80 .map_err(|err| error!(err.to_string()))?; 81 81 82 - Ok(crate::convert::from_message(&resp)?) 82 + crate::convert::from_message(&resp).map_err(|err| error!(err)) 83 83 } 84 84 }
+12 -12
src/convert.rs
··· 1 1 use dbus::{Message, arg::{ArgType, RefArg}}; 2 - use nu_plugin::LabeledError; 3 2 use nu_protocol::{Value, Span, Record}; 4 3 5 - pub fn from_message(message: &Message) -> Result<Value, LabeledError> { 4 + pub fn from_message(message: &Message) -> Result<Value, String> { 6 5 let mut out = vec![]; 7 6 for refarg in message.iter_init() { 8 - if let Some(o) = from_refarg(&refarg) { 9 - out.push(o); 10 - } 7 + out.push(from_refarg(&refarg)?); 11 8 } 12 9 Ok(Value::list(out, Span::unknown())) 13 10 } 14 11 15 - pub fn from_refarg(refarg: &dyn RefArg) -> Option<Value> { 16 - Some(match refarg.arg_type() { 12 + pub fn from_refarg(refarg: &dyn RefArg) -> Result<Value, String> { 13 + Ok(match refarg.arg_type() { 17 14 ArgType::Array => { 18 15 if refarg.signature().starts_with("a{") { 19 16 // This is a dictionary ··· 52 49 ArgType::Byte | ArgType::Int16 | ArgType::UInt16 | ArgType::Int32 | 53 50 ArgType::UInt32 | ArgType::Int64 | ArgType::UnixFd => 54 51 Value::int(refarg.as_i64().unwrap(), Span::unknown()), 52 + 53 + // Nushell doesn't support u64, so present it as a string 54 + ArgType::UInt64 => Value::string(refarg.as_u64().unwrap().to_string(), Span::unknown()), 55 + 55 56 // Floats 56 57 ArgType::Double => 57 58 Value::float(refarg.as_f64().unwrap(), Span::unknown()), ··· 61 62 refarg.as_iter().unwrap().map(from_refarg).flatten().collect(), 62 63 Span::unknown()), 63 64 64 - ArgType::DictEntry => todo!(), 65 - ArgType::UInt64 => todo!(), // nushell only supports up to i64 66 - 67 - // End of iterator 68 - ArgType::Invalid => return None, 65 + ArgType::DictEntry => 66 + return Err("Encountered dictionary entry outside of dictionary".into()), 67 + ArgType::Invalid => 68 + return Err("Encountered invalid D-Bus value".into()), 69 69 }) 70 70 }