More detailed error message in case of command parse error (#684)

* Refactored `command::parse`

* Removed unnecessary duplication in error msg

* Renamed `NotEnoughArgs` -> `InsufficientArgs`

* Inaccurate var name

* Ditch wordy error prefix

* Use `split_whitespace` instead of regex

* Cleanup unused regex import

* `insert` cmd fails fast

* Refactor: use `and_then` instead of `unwrap`

* Updated `Command::to_string`

* Added `Command::basename`

* Better err msg when running cmd in unsupported view, fully closes #597

* Sort `match` branches by their order in the enum
This commit is contained in:
cyqsimon
2022-01-02 03:48:34 +08:00
committed by GitHub
parent 075ecd0e24
commit 9771c36c7b
6 changed files with 562 additions and 304 deletions

View File

@@ -10,7 +10,7 @@ use cursive::view::ScrollBase;
use cursive::{Cursive, Printer, Rect, Vec2};
use unicode_width::UnicodeWidthStr;
use crate::command::{Command, GotoMode, JumpMode, MoveAmount, MoveMode, TargetMode};
use crate::command::{Command, GotoMode, InsertSource, JumpMode, MoveAmount, MoveMode, TargetMode};
use crate::commands::CommandResult;
use crate::library::Library;
use crate::model::album::Album;
@@ -520,20 +520,15 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
}
}
}
Command::Insert(url) => {
let url = match url.as_ref().map(String::as_str) {
Command::Insert(source) => {
let url = match source {
InsertSource::Input(url) => Some(url.clone()),
#[cfg(feature = "share_clipboard")]
Some("") | None => read_share().unwrap(),
Some(url) => url.to_owned(),
// do nothing if clipboard feature is disabled and there is no url provided
#[allow(unreachable_patterns)]
_ => return Ok(CommandResult::Consumed(None)),
InsertSource::Clipboard => read_share().and_then(SpotifyUrl::from_url),
};
let spotify = self.queue.get_spotify();
let url = SpotifyUrl::from_url(&url);
if let Some(url) = url {
let target: Option<Box<dyn ListItem>> = match url.uri_type {
UriType::Track => spotify