Add option to copy ffsend download command instead of share URL using -C
This commit is contained in:
parent
e1d0ddee0d
commit
b697bc3231
6 changed files with 66 additions and 28 deletions
25
README.md
25
README.md
|
@ -302,18 +302,19 @@ These environment variables may be used to toggle a flag, simply by making them
|
|||
available. The actual value of these variables is ignored, and variables may be
|
||||
empty.
|
||||
|
||||
| Variable | CLI flag | Description |
|
||||
| :------------------- | :-------------: | :-------------------------------- |
|
||||
| `FFSEND_FORCE` | `--force` | Force operations |
|
||||
| `FFSEND_NO_INTERACT` | `--no-interact` | No interaction for prompts |
|
||||
| `FFSEND_YES` | `--yes` | Assume yes for prompts |
|
||||
| `FFSEND_INCOGNITO` | `--incognito` | Incognito mode, don't use history |
|
||||
| `FFSEND_OPEN` | `--open` | Open share link of uploaded file |
|
||||
| `FFSEND_ARCHIVE` | `--archive` | Archive files uploaded |
|
||||
| `FFSEND_EXTRACT` | `--extract` | Extract files downloaded |
|
||||
| `FFSEND_COPY` | `--copy` | Copy share link to clipboard |
|
||||
| `FFSEND_QUIET` | `--quiet` | Log quiet information |
|
||||
| `FFSEND_VERBOSE` | `--verbose` | Log verbose information |
|
||||
| Variable | CLI flag | Description |
|
||||
| :------------------- | :-------------: | :--------------------------------- |
|
||||
| `FFSEND_FORCE` | `--force` | Force operations |
|
||||
| `FFSEND_NO_INTERACT` | `--no-interact` | No interaction for prompts |
|
||||
| `FFSEND_YES` | `--yes` | Assume yes for prompts |
|
||||
| `FFSEND_INCOGNITO` | `--incognito` | Incognito mode, don't use history |
|
||||
| `FFSEND_OPEN` | `--open` | Open share link of uploaded file |
|
||||
| `FFSEND_ARCHIVE` | `--archive` | Archive files uploaded |
|
||||
| `FFSEND_EXTRACT` | `--extract` | Extract files downloaded |
|
||||
| `FFSEND_COPY` | `--copy` | Copy share link to clipboard |
|
||||
| `FFSEND_COPY_CMD` | `--copy-cmd` | Copy download command to clipboard |
|
||||
| `FFSEND_QUIET` | `--quiet` | Log quiet information |
|
||||
| `FFSEND_VERBOSE` | `--verbose` | Log verbose information |
|
||||
|
||||
At this time, no configuration or _dotfile_ file support is available.
|
||||
This will be something added in a later release.
|
||||
|
|
|
@ -19,15 +19,15 @@ use super::select_api_version;
|
|||
#[cfg(feature = "archive")]
|
||||
use crate::archive::archiver::Archiver;
|
||||
use crate::client::create_transfer_client;
|
||||
use crate::cmd::matcher::{MainMatcher, Matcher, UploadMatcher};
|
||||
use crate::cmd::matcher::{CopyMode, MainMatcher, Matcher, UploadMatcher};
|
||||
#[cfg(feature = "history")]
|
||||
use crate::history_tool;
|
||||
use crate::progress::ProgressBar;
|
||||
#[cfg(feature = "clipboard")]
|
||||
use crate::util::set_clipboard;
|
||||
use crate::util::{
|
||||
format_bytes, open_url, print_error, print_error_msg, prompt_yes, quit, quit_error_msg,
|
||||
ErrorHintsBuilder,
|
||||
bin_name, format_bytes, open_url, print_error, print_error_msg, prompt_yes, quit,
|
||||
quit_error_msg, ErrorHintsBuilder,
|
||||
};
|
||||
|
||||
/// A file upload action.
|
||||
|
@ -268,8 +268,15 @@ impl<'a> Upload<'a> {
|
|||
// Copy the URL in the user's clipboard
|
||||
#[cfg(feature = "clipboard")]
|
||||
{
|
||||
if matcher_upload.copy() {
|
||||
if let Err(err) = set_clipboard(url.as_str().to_owned()) {
|
||||
if let Some(copy_mode) = matcher_upload.copy() {
|
||||
// Build the string to copy
|
||||
let copy = match copy_mode {
|
||||
CopyMode::Url => url.as_str().to_owned(),
|
||||
CopyMode::DownloadCmd => format!("{} download {}", bin_name(), url.as_str()),
|
||||
};
|
||||
|
||||
// Copy to clipboard
|
||||
if let Err(err) = set_clipboard(copy) {
|
||||
print_error(
|
||||
err.context("failed to copy the share link to the clipboard, ignoring"),
|
||||
);
|
||||
|
|
|
@ -22,7 +22,7 @@ pub use self::info::InfoMatcher;
|
|||
pub use self::main::MainMatcher;
|
||||
pub use self::params::ParamsMatcher;
|
||||
pub use self::password::PasswordMatcher;
|
||||
pub use self::upload::UploadMatcher;
|
||||
pub use self::upload::{CopyMode, UploadMatcher};
|
||||
pub use self::version::VersionMatcher;
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
|
|
@ -93,10 +93,21 @@ impl<'a: 'b, 'b> UploadMatcher<'a> {
|
|||
self.matches.is_present("open") || env_var_present("FFSEND_OPEN")
|
||||
}
|
||||
|
||||
/// Check whether to copy the file URL in the user's clipboard.
|
||||
/// Check whether to copy the file URL in the user's clipboard, get the copy mode.
|
||||
#[cfg(feature = "clipboard")]
|
||||
pub fn copy(&self) -> bool {
|
||||
self.matches.is_present("copy") || env_var_present("FFSEND_COPY")
|
||||
pub fn copy(&self) -> Option<CopyMode> {
|
||||
// Get the options
|
||||
let copy = self.matches.is_present("copy") || env_var_present("FFSEND_COPY");
|
||||
let copy_cmd = self.matches.is_present("copy-cmd") || env_var_present("FFSEND_COPY_CMD");
|
||||
|
||||
// Return the corresponding copy mode
|
||||
if copy_cmd {
|
||||
Some(CopyMode::DownloadCmd)
|
||||
} else if copy {
|
||||
Some(CopyMode::Url)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,3 +118,12 @@ impl<'a> Matcher<'a> for UploadMatcher<'a> {
|
|||
.map(|matches| UploadMatcher { matches })
|
||||
}
|
||||
}
|
||||
|
||||
/// The copy mode.
|
||||
pub enum CopyMode {
|
||||
/// Copy the public share link.
|
||||
Url,
|
||||
|
||||
/// Copy an ffsend download command.
|
||||
DownloadCmd,
|
||||
}
|
||||
|
|
|
@ -55,12 +55,22 @@ impl CmdUpload {
|
|||
// Optional clipboard support
|
||||
#[cfg(feature = "clipboard")]
|
||||
{
|
||||
cmd = cmd.arg(
|
||||
Arg::with_name("copy")
|
||||
.long("copy")
|
||||
.short("c")
|
||||
.help("Copy the share link to your clipboard"),
|
||||
);
|
||||
cmd = cmd
|
||||
.arg(
|
||||
Arg::with_name("copy")
|
||||
.long("copy")
|
||||
.short("c")
|
||||
.help("Copy the share link to your clipboard")
|
||||
.conflicts_with("copy-cmd"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("copy-cmd")
|
||||
.long("copy-cmd")
|
||||
.alias("copy-command")
|
||||
.short("C")
|
||||
.help("Copy the ffsend download command to your clipboard")
|
||||
.conflicts_with("copy"),
|
||||
);
|
||||
}
|
||||
|
||||
cmd
|
||||
|
|
|
@ -413,7 +413,7 @@ pub fn prompt_password(main_matcher: &MainMatcher, optional: bool) -> Option<Str
|
|||
ErrorHints::default(),
|
||||
)
|
||||
} else {
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue