diff --git a/src/lib.rs b/src/lib.rs index 17ab3b7..6e5bc29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ use serde_json::json; use std::error::Error; use std::fs; use std::io; +use std::io::Write; use std::path::Path; // #[derive(Debug)] @@ -162,7 +163,8 @@ fn file_url(client: &Client, file_id: i64) -> Result> { } pub fn run(config: Config) -> Result<(), Box> { - // let files: Files = serde_json::from_str(data)?; + let stdout = io::stdout(); + let mut handle = stdout.lock(); let path = Path::new("."); let downloaded_files = list_dir(&path).unwrap(); let client = Client::new(&config.oauth_token); @@ -171,7 +173,7 @@ pub fn run(config: Config) -> Result<(), Box> { if file.file_type == "VIDEO" { let download_url = file_url(&client, file.id).unwrap(); if downloaded_files.iter().find(|&x| x == &file.name) == None { - println!("{}", download_url); + writeln!(handle, "{}", download_url)?; } else { if file.parent_id != config.parent_id { delete_file(&client, file.parent_id).unwrap(); diff --git a/src/main.rs b/src/main.rs index c3ad78d..c384a20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,25 @@ use std::env; +use std::io::{self, Result, Write}; use std::process; use putio::run; use putio::Config; -fn main() { +fn main() -> Result<()> { let args: Vec = env::args().collect(); + let stdout = io::stdout(); let config = Config::new(&args).unwrap_or_else(|err| { - println!("\r\nProblems parsing arguments: {}\r\n", err); + let mut handle = stdout.lock(); + writeln!(handle, "\r\nProblems parsing arguments: {}\r\n", err).unwrap(); process::exit(1); }); if let Err(err) = run(config) { - println!("\r\nError: {}\r\n", err); + let mut handle = stdout.lock(); + writeln!(handle, "\r\nError: {}\r\n", err).unwrap(); process::exit(1); } + Ok(()) }