Require user to set file name when archiving multiple files

This commit is contained in:
timvisee 2019-06-20 21:29:32 +02:00
parent a7582ae765
commit dee5289597
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
2 changed files with 25 additions and 2 deletions

View file

@ -123,8 +123,20 @@ impl<'a> Upload<'a> {
.map_err(ArchiveError::CloneHandle)?;
// Select the file name to use if not set
// TODO: require user to define if multiple paths
if file_name.is_none() {
// Require user to specify name if multiple files are given
if paths.len() > 1 {
quit_error_msg(
"you must specify a file name for the archive",
ErrorHintsBuilder::default()
.name(true)
.verbose(false)
.build()
.unwrap(),
);
}
// Derive name from given file
file_name = Some(
path.canonicalize()
.map_err(|err| ArchiveError::FileName(Some(err)))?

View file

@ -132,6 +132,9 @@ pub struct ErrorHints {
/// A list of info messages to print along with the error.
info: Vec<String>,
/// Show about the name option.
name: bool,
/// Show about the password option.
password: bool,
@ -157,7 +160,8 @@ impl ErrorHints {
pub fn any(&self) -> bool {
// Determine the result
#[allow(unused_mut)]
let mut result = self.password || self.owner || self.force || self.verbose || self.help;
let mut result =
self.name || self.password || self.owner || self.force || self.verbose || self.help;
// Factor in the history hint when enabled
#[cfg(feature = "history")]
@ -189,6 +193,12 @@ impl ErrorHints {
highlight("--api <VERSION>")
);
}
if self.name {
eprintln!(
"Use '{}' to specify a file name",
highlight("--name <NAME>")
);
}
if self.password {
eprintln!(
"Use '{}' to specify a password",
@ -230,6 +240,7 @@ impl Default for ErrorHints {
ErrorHints {
api: false,
info: Vec::new(),
name: false,
password: false,
owner: false,
#[cfg(feature = "history")]