Require user to set file name when archiving multiple files
This commit is contained in:
parent
a7582ae765
commit
dee5289597
2 changed files with 25 additions and 2 deletions
|
@ -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)))?
|
||||
|
|
13
src/util.rs
13
src/util.rs
|
@ -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")]
|
||||
|
|
Loading…
Reference in a new issue