xous-core/services/shellchat/src/cmds/pddb_cmd.rs

52 lines
1.7 KiB
Rust
Raw Normal View History

2022-01-06 06:50:44 +00:00
use crate::{ShellCmdApi, CommonEnv};
use xous_ipc::String;
pub struct PddbCmd {
2022-01-07 07:43:50 +00:00
pddb: pddb::Pddb,
2022-01-06 06:50:44 +00:00
}
impl PddbCmd {
pub fn new(_xns: &xous_names::XousNames) -> PddbCmd {
2022-01-06 06:50:44 +00:00
PddbCmd {
2022-01-07 07:43:50 +00:00
pddb: pddb::Pddb::new(),
2022-01-06 06:50:44 +00:00
}
}
}
impl<'a> ShellCmdApi<'a> for PddbCmd {
cmd_api!(pddb); // inserts boilerplate for command API
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
2022-01-06 06:50:44 +00:00
use core::fmt::Write;
let mut ret = String::<1024>::new();
let helpstring = "pddb [basislist]";
let mut tokens = args.as_str().unwrap().split(' ');
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"basislist" => {
2022-01-07 07:43:50 +00:00
let bases = self.pddb.list_basis();
2022-01-06 06:50:44 +00:00
for basis in bases {
write!(ret, "{}\n", basis).unwrap();
}
/* // example of using .get with a callback
2022-01-07 07:43:50 +00:00
self.pddb.get("foo", "bar", None, false, false,
Some({
let cid = cid.clone();
let counter = self.counter.clone();
move || {
xous::send_message(cid, xous::Message::new_scalar(0, counter as usize, 0, 0, 0)).expect("couldn't send");
}})
).unwrap();*/
2022-01-06 06:50:44 +00:00
}
_ => {
write!(ret, "{}", helpstring).unwrap();
}
}
} else {
write!(ret, "{}", helpstring).unwrap();
}
Ok(Some(ret))
}
}