diff options
| author | Arne Dußin | 2021-01-27 14:01:50 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-02 22:16:15 +0100 |
| commit | f92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch) | |
| tree | 20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/cli/cmd/read.rs | |
| parent | c60a6d07efb120724b308e29e8e70f27c87c952d (diff) | |
| download | graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip | |
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/cli/cmd/read.rs')
| -rw-r--r-- | src/cli/cmd/read.rs | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/src/cli/cmd/read.rs b/src/cli/cmd/read.rs deleted file mode 100644 index 45cdf99..0000000 --- a/src/cli/cmd/read.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Read the contents of a file and add it to the currently edited map. - -use super::Command; -use super::{CmdParseError, FromArgs}; -use crate::map::MapData; -use crate::Editor; -use std::path::PathBuf; - -/// Command to read a file from the system -pub struct Read { - file: PathBuf, -} - -impl FromArgs for Read { - fn from_args(args: &[&str]) -> Result<Self, CmdParseError> { - if args.len() != 1 { - return Err(CmdParseError::WrongNumberOfArgs(args.len(), 1..=1)); - } - - Ok(Self { - file: PathBuf::from(args[0]), - }) - } -} - -impl Command for Read { - fn process(&self, editor: &mut Editor) -> Result<String, String> { - let data = match MapData::load_from_file(&self.file) { - Ok(data) => data, - Err(err) => { - return Err(format!( - "Unable to read file: {:?}, reason: {:?}", - &self.file, err - )) - } - }; - - editor.map_mut().add_data(data); - Ok(format!( - "Map data from {:?} read and added to the current buffer.", - &self.file - )) - } -} |
