*/
use buffer::Buffer;
+use storage::Storage;
pub struct Shell<'a> {
tx_buf: &'a mut Buffer,
}
}
+struct Context<'a> {
+ storage: &'a mut dyn Storage,
+}
+
impl<'a> Shell<'a> {
pub fn new(tx_buf: &mut Buffer) -> Shell {
Shell {
}
}
- pub fn update(&mut self) {
+ pub fn update(&mut self, storage: &mut dyn Storage) {
+ let mut context = Context {
+ storage: storage,
+ };
+
while let Some(c) = read_char() {
if c != b'\n' {
if self.command_offset != self.command_buffer.len() {
self.command_buffer[command_length] = b'\0';
if command_length != 0 {
- self.dispatch(command_length);
+ self.dispatch(command_length, &mut context);
}
} else {
self.command_buffer[self.command_offset] = b'\0';
}
}
- fn dispatch(&mut self, command_length: usize) {
+ fn dispatch(&mut self, command_length: usize, mut context: &mut Context) {
let command : [u8; 32] = self.command_buffer;
let mut args_iter = ArgumentIter {
let usage = b"\
Supported commands:
help Show this help message.
+ clear_storage Fully erase the flash's contents.
";
self.tx_buf.write(usage);
},
+ Some(b"clear_storage") => self.run_clear_storage(&mut context),
+
Some(ref other) => {
self.tx_buf.write(b"unknown_command: ");
self.tx_buf.write(other);
}
}
}
+
+ fn run_clear_storage(&self, context: &mut Context) {
+ context.storage.clear();
+ }
}