From 6626c929cf70e6a9a757cc6009147dcb41d8bd5c Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 3 Jul 2018 19:59:53 +0300 Subject: Add input file path validation --- src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 408094a..932d9af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,21 +3,31 @@ extern crate colored; extern crate rustyline; use colored::*; -use clap::{Arg, App, SubCommand}; -use rustyline::error::ReadlineError; -use rustyline::Editor; +use clap::{Arg, App}; +// use rustyline::error::ReadlineError; +// use rustyline::Editor; +use std::path::Path; +use std::process; fn main() { let matches = App::new("Rustcast") .version("0.1") .author("Yuval Adam") .about("A simple UPnP/DLNA casting player") - .arg(Arg::with_name("file") + .arg(Arg::with_name("FILE") .value_name("FILE") .help("Media file to stream") .index(1) .required(true)) .get_matches(); - //println!("\n{}", "Rustcast v0.1.0".color("blue").bold()); - //println!("\n usage: rustcast \n"); + + let infile = matches.value_of("FILE").unwrap(); + + if Path::new(infile).exists() { + println!("\n{} {}\n", "Using input file:".green(), infile.green()); + } + else { + println!("\n{} {}\n", "Input file does not exist:".red(), infile.red()); + process::exit(1); + } } -- cgit v1.3.1