Przeglądaj źródła

Implement archive and history flags properly, resolve warnings

timvisee 7 lat temu
rodzic
commit
d0cbf800f2

+ 1 - 0
cli/src/action/debug.rs

@@ -47,6 +47,7 @@ impl<'a> Debug<'a> {
         ]));
 
         // The history file
+        #[cfg(feature = "history")]
         table.add_row(Row::new(vec![
             Cell::new("History file:"),
             Cell::new(matcher_main.history().to_str().unwrap_or("?")),

+ 7 - 0
cli/src/action/download.rs

@@ -1,5 +1,6 @@
 use std::env::current_dir;
 use std::fs::create_dir_all;
+#[cfg(feature = "archive")]
 use std::io::Error as IoError;
 use std::path::{self, PathBuf};
 use std::sync::{Arc, Mutex};
@@ -21,6 +22,7 @@ use ffsend_api::action::metadata::{
 use ffsend_api::file::remote_file::{FileParseError, RemoteFile};
 use ffsend_api::reader::ProgressReporter;
 use ffsend_api::reqwest::Client;
+#[cfg(feature = "archive")]
 use tempfile::{
     Builder as TempBuilder,
     NamedTempFile,
@@ -126,12 +128,14 @@ impl<'a> Download<'a> {
         let output_dir = !extract;
         #[cfg(not(feature = "archive"))]
         let output_dir = false;
+        #[allow(unused_mut)]
         let mut target = Self::prepare_path(
             &target,
             metadata.metadata().name(),
             &matcher_main,
             output_dir,
         );
+        #[cfg(feature = "archive")]
         let output_path = target.clone();
 
         #[cfg(feature = "archive")] {
@@ -365,6 +369,7 @@ pub enum Error {
     Download(#[cause] DownloadError),
 
     /// An error occurred while extracting the file.
+    #[cfg(feature = "archive")]
     #[fail(display = "failed the extraction procedure")]
     Extract(#[cause] ExtractError),
 
@@ -397,12 +402,14 @@ impl From<DownloadError> for Error {
     }
 }
 
+#[cfg(feature = "archive")]
 impl From<ExtractError> for Error {
     fn from(err: ExtractError) -> Error {
         Error::Extract(err)
     }
 }
 
+#[cfg(feature = "archive")]
 #[derive(Debug, Fail)]
 pub enum ExtractError {
     /// An error occurred while creating the temporary archive file.

+ 9 - 0
cli/src/action/upload.rs

@@ -1,4 +1,5 @@
 use std::fs::File;
+#[cfg(feature = "archive")]
 use std::io::Error as IoError;
 use std::path::Path;
 use std::sync::{Arc, Mutex};
@@ -19,6 +20,7 @@ use prettytable::{
     row::Row,
     Table,
 };
+#[cfg(feature = "archive")]
 use tempfile::{
     Builder as TempBuilder,
     NamedTempFile,
@@ -64,6 +66,7 @@ impl<'a> Upload<'a> {
         let matcher_upload = UploadMatcher::with(self.cmd_matches).unwrap();
 
         // Get API parameters
+        #[allow(unused_mut)]
         let mut path = Path::new(matcher_upload.file()).to_path_buf();
         let host = matcher_upload.host();
 
@@ -129,10 +132,13 @@ impl<'a> Upload<'a> {
         };
 
         // The file name to use
+        #[allow(unused_mut)]
         let mut file_name = matcher_upload.name().map(|s| s.to_owned());
 
         // A temporary archive file, only used when archiving
         // The temporary file is stored here, to ensure it's lifetime exceeds the upload process
+        #[allow(unused_mut)]
+        #[cfg(feature = "archive")]
         let mut tmp_archive: Option<NamedTempFile> = None;
 
         #[cfg(feature = "archive")] {
@@ -265,6 +271,7 @@ impl<'a> Upload<'a> {
 #[derive(Debug, Fail)]
 pub enum Error {
     /// An error occurred while archiving the file to upload.
+    #[cfg(feature = "archive")]
     #[fail(display = "failed to archive file to upload")]
     Archive(#[cause] ArchiveError),
 
@@ -273,6 +280,7 @@ pub enum Error {
     Upload(#[cause] UploadError),
 }
 
+#[cfg(feature = "archive")]
 impl From<ArchiveError> for Error {
     fn from(err: ArchiveError) -> Error {
         Error::Archive(err)
@@ -285,6 +293,7 @@ impl From<UploadError> for Error {
     }
 }
 
+#[cfg(feature = "archive")]
 #[derive(Debug, Fail)]
 pub enum ArchiveError {
     /// An error occurred while creating the temporary archive file.

+ 1 - 0
cli/src/cmd/matcher/download.rs

@@ -5,6 +5,7 @@ use ffsend_api::url::Url;
 
 use cmd::arg::{ArgPassword, ArgUrl, CmdArgOption};
 use super::Matcher;
+#[cfg(feature = "archive")]
 use util::env_var_present;
 
 /// The download command matcher.

+ 2 - 1
cli/src/cmd/matcher/main.rs

@@ -4,8 +4,9 @@ use std::path::PathBuf;
 use clap::ArgMatches;
 
 use super::Matcher;
+use util::env_var_present;
 #[cfg(feature = "history")]
-use util::{env_var_present, ErrorHintsBuilder, quit_error_msg};
+use util::{ErrorHintsBuilder, quit_error_msg};
 
 /// The main command matcher.
 pub struct MainMatcher<'a> {

+ 1 - 0
cli/src/cmd/subcmd/download.rs

@@ -8,6 +8,7 @@ pub struct CmdDownload;
 impl CmdDownload {
     pub fn build<'a, 'b>() -> App<'a, 'b> {
         // Build the subcommand
+        #[allow(unused_mut)]
         let mut cmd = SubCommand::with_name("download")
             .about("Download files")
             .visible_alias("d")