mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-05 18:24:18 +02:00
Allow specifying an output file or directory when downloading [WIP]
This commit is contained in:
parent
649190b17a
commit
8259106c17
5 changed files with 109 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue