Allow specifying an output file or directory when downloading [WIP]

This commit is contained in:
timvisee 2018-03-29 22:50:43 +02:00
parent 649190b17a
commit 8259106c17
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
5 changed files with 109 additions and 22 deletions

View file

@ -34,12 +34,18 @@ impl<'a> Download<'a> {
// TODO: handle error here
let file = RemoteFile::parse_url(url, None)?;
// Get the target file or directory
let target = self.cmd.file();
// Create a progress bar reporter
let bar = Arc::new(Mutex::new(ProgressBar::new_download()));
// Execute an download action
ApiDownload::new(&file, self.cmd.password())
.invoke(&client, bar)?;
ApiDownload::new(
&file,
target,
self.cmd.password(),
).invoke(&client, bar)?;
// TODO: open the file, or it's location
// TODO: copy the file location

View file

@ -1,3 +1,5 @@
use std::path::PathBuf;
use ffsend_api::url::{ParseError, Url};
use super::clap::{App, Arg, ArgMatches, SubCommand};
@ -23,6 +25,11 @@ impl<'a: 'b, 'b> CmdDownload<'a> {
.help("The share URL")
.required(true)
.multiple(false))
.arg(Arg::with_name("file")
.long("file")
.short("f")
.value_name("PATH")
.help("The output file or directory"))
.arg(Arg::with_name("password")
.long("password")
.short("p")
@ -71,6 +78,15 @@ impl<'a: 'b, 'b> CmdDownload<'a> {
}
}
/// The target file or directory to download the file to.
/// If a directory is given, the file name of the original uploaded file
/// will be used.
pub fn file(&'a self) -> PathBuf {
self.matches.value_of("file")
.map(|path| PathBuf::from(path))
.unwrap_or(PathBuf::from("./"))
}
/// Get the password.
/// `None` is returned if no password was specified.
pub fn password(&'a self) -> Option<String> {