From b0ba131fbae07787bcac2149464eebb0c6272aa3 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Tue, 11 Feb 2020 19:57:21 +0100 Subject: [PATCH] common: Implement the "rm" shell command. Removes a recording. --- src/common/shell.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/shell.rs b/src/common/shell.rs index 097bd0c..e48a5de 100644 --- a/src/common/shell.rs +++ b/src/common/shell.rs @@ -199,6 +199,7 @@ Supported commands: help Show this help message. ls List recordings. get REC_ID Retrieve recording. + rm REC_ID Remove recording. clear_storage Fully erase the flash's contents. dump_storage Dump the flash's contents. "; @@ -208,6 +209,7 @@ Supported commands: Some(b"ls") => self.run_ls(logger), Some(b"get") => self.run_get(logger, &mut args_iter), + Some(b"rm") => self.run_rm(logger, &mut args_iter), Some(b"clear_storage") => self.run_clear_storage(logger), Some(b"dump_storage") => self.run_dump_storage(logger), @@ -264,6 +266,28 @@ Supported commands: self.tx_buf.flush(); } + fn run_rm(&mut self, logger: &mut Logger, args_iter: &mut ArgumentIter) { + if let Some(recording_id_s) = args_iter.next() { + if let Some(recording_id) = atoi16(recording_id_s) { + if logger.has_recording(recording_id) { + let result = logger.remove_recording(recording_id); + + if result.is_err() { + self.tx_buf.write(b"rm: failed to remove recording\n"); + } + } else { + self.tx_buf.write(b"rm: no such recording\n"); + } + } else { + self.tx_buf.write(b"rm: invalid argument\n"); + } + } else { + self.tx_buf.write(b"rm: missing argument\n"); + } + + self.tx_buf.flush(); + } + fn run_clear_storage(&self, logger: &mut Logger) { logger.storage.clear(); } -- 2.30.2