mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-21 20:39:47 -04:00
wip: update the command syntax to be more future proof
This commit is contained in:
parent
4dd0365bdd
commit
7e4109e734
@ -12,6 +12,7 @@ The currently supported commands are:
|
||||
* `new-sheet [name]` Creates a new sheet. If the name is provided then uses that. If omitted then uses a default sheet name.
|
||||
* `select-sheet <name>` Select a sheet by name.
|
||||
* `edit <path>` Edit a new spreadsheet at the current path. `e` is a shorthand alias for this command.
|
||||
* `export-csv <path>` Export the current sheet to a csv file at `<path>`.
|
||||
* `quit` Quits the application. `q` is a shorthand alias for this command.
|
||||
|
||||
<aside>Note that in the case of `quit` and `edit` that we do not currently
|
||||
|
@ -120,7 +120,8 @@ impl Book {
|
||||
}
|
||||
|
||||
pub fn csv_for_sheet<W>(&self, sheet: u32, sink: W) -> Result<()>
|
||||
where W: std::io::Write,
|
||||
where
|
||||
W: std::io::Write,
|
||||
{
|
||||
let rows = self.get_export_rows_for_sheet(sheet)?;
|
||||
let mut writer = csv::Writer::from_writer(sink);
|
||||
|
@ -15,7 +15,7 @@ pub enum Cmd<'a> {
|
||||
SelectSheet(&'a str),
|
||||
Edit(&'a str),
|
||||
Help(Option<&'a str>),
|
||||
Export(&'a str),
|
||||
ExportCsv(&'a str),
|
||||
Quit,
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ pub fn parse<'cmd, 'i: 'cmd>(input: &'i str) -> Result<Option<Cmd<'cmd>>, &'stat
|
||||
return Ok(Some(cmd));
|
||||
}
|
||||
// Try consume export
|
||||
if let Some(cmd) = try_consume_export(cursor.clone())? {
|
||||
if let Some(cmd) = try_consume_export_csv(cursor.clone())? {
|
||||
return Ok(Some(cmd));
|
||||
}
|
||||
// try consume edit command.
|
||||
@ -114,17 +114,13 @@ fn try_consume_write<'cmd, 'i: 'cmd>(
|
||||
})));
|
||||
}
|
||||
|
||||
fn try_consume_export<'cmd, 'i: 'cmd>(
|
||||
fn try_consume_export_csv<'cmd, 'i: 'cmd>(
|
||||
mut input: StrCursor<'i>,
|
||||
) -> Result<Option<Cmd<'cmd>>, &'static str> {
|
||||
const SHORT: &'static str = "ex";
|
||||
const LONG: &'static str = "export";
|
||||
const LONG: &'static str = "export-csv";
|
||||
|
||||
if compare(input.clone(), LONG) {
|
||||
input.seek(LONG.len());
|
||||
} else if compare(input.clone(), SHORT) {
|
||||
input.seek(SHORT.len());
|
||||
// Should we check for whitespace?
|
||||
} else {
|
||||
return Ok(None);
|
||||
}
|
||||
@ -132,7 +128,7 @@ fn try_consume_export<'cmd, 'i: 'cmd>(
|
||||
return Err("Invalid command: Did you mean to type `export <path>`?");
|
||||
}
|
||||
let arg = input.span(0..).trim();
|
||||
return Ok(Some(Cmd::Export(arg)));
|
||||
return Ok(Some(Cmd::ExportCsv(arg)));
|
||||
}
|
||||
|
||||
fn try_consume_new_sheet<'cmd, 'i: 'cmd>(
|
||||
|
@ -425,7 +425,7 @@ impl<'ws> Workspace<'ws> {
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
Ok(Some(Cmd::Export(path))) => {
|
||||
Ok(Some(Cmd::ExportCsv(path))) => {
|
||||
self.book.save_sheet_to_csv(self.book.location.sheet, path)?;
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ fn test_cmd_new_sheet_with_name() {
|
||||
|
||||
#[test]
|
||||
fn test_cmd_export() {
|
||||
let input = "export test.csv";
|
||||
let input = "export-csv test.csv";
|
||||
let result = parse(input);
|
||||
assert!(result.is_ok());
|
||||
let output = result.unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user