Added autcompletions.
Description: - Added autocompletions for some shells. - Fixed styles. - Fixed possible bugs with clippy. Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
@ -1,30 +1,19 @@
|
||||
use crate::{Opt, RunMode};
|
||||
use crate::result::{AppResult, AppError};
|
||||
use crate::config::{update_config, update_episode, Config};
|
||||
use crate::initialization::init_config;
|
||||
use crate::config::{update_episode, update_config, Config};
|
||||
use crate::result::{AppError, AppResult};
|
||||
use crate::{generate_completion, Opt, RunMode};
|
||||
use std::process::Command;
|
||||
|
||||
pub fn run(opts: Opt) -> AppResult<()> {
|
||||
let mode = opts.mode.unwrap_or_else(|| RunMode::Play);
|
||||
match mode {
|
||||
RunMode::Init => {
|
||||
init_config()
|
||||
}
|
||||
RunMode::Play => {
|
||||
play()
|
||||
}
|
||||
RunMode::Prev => {
|
||||
update_episode(prev_episode)
|
||||
}
|
||||
RunMode::Next => {
|
||||
update_episode(next_episode)
|
||||
}
|
||||
RunMode::Update => {
|
||||
update_config()
|
||||
}
|
||||
RunMode::Reset => {
|
||||
update_episode(|_| { Ok(0) })
|
||||
}
|
||||
RunMode::Init => init_config(),
|
||||
RunMode::Play => play(),
|
||||
RunMode::Prev => update_episode(prev_episode),
|
||||
RunMode::Next => update_episode(next_episode),
|
||||
RunMode::Update => update_config(),
|
||||
RunMode::Reset => update_episode(|_| Ok(0)),
|
||||
RunMode::Completion { shell } => generate_completion(shell),
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,9 +21,9 @@ pub fn prev_episode(current: usize) -> AppResult<usize> {
|
||||
if let Some(episode) = current.checked_sub(1) {
|
||||
Ok(episode)
|
||||
} else {
|
||||
Err(AppError::RuntimeError(
|
||||
String::from("Episode can't be less than zero.")
|
||||
))
|
||||
Err(AppError::RuntimeError(String::from(
|
||||
"Episode can't be less than zero.",
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,9 +31,9 @@ pub fn next_episode(current: usize) -> AppResult<usize> {
|
||||
if let Some(episode) = current.checked_add(1) {
|
||||
Ok(episode)
|
||||
} else {
|
||||
Err(AppError::RuntimeError(
|
||||
String::from("Reached usize limit. Sorry.")
|
||||
))
|
||||
Err(AppError::RuntimeError(String::from(
|
||||
"Reached usize limit. Sorry.",
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +47,8 @@ fn add_leading_zero(n: usize) -> String {
|
||||
|
||||
fn prepare_command(conf: Config) -> AppResult<String> {
|
||||
let index = conf.current_episode_count;
|
||||
Ok(conf.command
|
||||
Ok(conf
|
||||
.command
|
||||
.replace("{}", conf.get_current_episode()?.as_str())
|
||||
.replace("{n}", format!("{}", index).as_str())
|
||||
.replace("{n+}", format!("{}", index + 1).as_str())
|
||||
@ -80,4 +70,4 @@ pub fn play() -> AppResult<()> {
|
||||
episode = conf.get_current_episode()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user