Return result of Command::execute directly from main #7

Closed
MarkusPettersson98 wants to merge 1 commit from main-returns-result into main
2 changed files with 5 additions and 9 deletions
Showing only changes of commit 50485e7c3a - Show all commits

View file

@ -1,6 +1,6 @@
use std::io; use std::io;
use std::fmt; use std::fmt;
use std::fmt::Display; use std::fmt::Debug;
pub enum FF2MpvError { pub enum FF2MpvError {
NoConfig, NoConfig,
@ -20,7 +20,7 @@ impl From<serde_json::Error> for FF2MpvError {
} }
} }
impl Display for FF2MpvError { impl Debug for FF2MpvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NoConfig => write!(f, "Config doesn't exist"), Self::NoConfig => write!(f, "Config doesn't exist"),

View file

@ -1,18 +1,14 @@
use std::env; use std::env;
use std::process;
use ff2mpv_rust::command::Command; use ff2mpv_rust::{command::Command, error::FF2MpvError};
fn main() { fn main() -> Result<(), FF2MpvError> {
let mut args = env::args(); let mut args = env::args();
args.next(); // Skip binary path args.next(); // Skip binary path
let command_name = args.next().unwrap_or_default(); let command_name = args.next().unwrap_or_default();
let command = get_command(&command_name); let command = get_command(&command_name);
if let Err(e) = command.execute() { command.execute()
eprintln!("{e}");
process::exit(-1);
}
} }
fn get_command(name: &str) -> Command { fn get_command(name: &str) -> Command {