diff options
| author | Yuval Adam <_@yuv.al> | 2018-07-03 19:59:53 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-07-03 19:59:53 +0300 |
| commit | 6626c929cf70e6a9a757cc6009147dcb41d8bd5c (patch) | |
| tree | 51a99917b699c3e5ce085846703280818051425e | |
| parent | 80cd9765b6a3083582329b1e7c63e861f7a81a45 (diff) | |
Add input file path validation
| -rw-r--r-- | src/main.rs | 22 |
1 files changed, 16 insertions, 6 deletions
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 <media.file>\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); + } } |
