Browse Source

Update ffsend-api dependency, hide progress bars in quiet mode

timvisee 6 years ago
parent
commit
c72e106de8
5 changed files with 44 additions and 25 deletions
  1. 4 0
      .gitlab-ci.yml
  2. 3 3
      Cargo.lock
  3. 1 1
      Cargo.toml
  4. 6 1
      src/action/download.rs
  5. 30 20
      src/action/upload.rs

+ 4 - 0
.gitlab-ci.yml

@@ -50,6 +50,10 @@ rust-nightly:
   <<: *check-base
   variables:
     RUST_VERSION: nightly
+# rust-old:
+#   <<: *check-base
+#   variables:
+#     RUST_VERSION: "1.26"
 
 # Build using Rust stable
 build:

+ 3 - 3
Cargo.lock

@@ -480,7 +480,7 @@ dependencies = [
  "derive_builder 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "directories 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "ffsend-api 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ffsend-api 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -498,7 +498,7 @@ dependencies = [
 
 [[package]]
 name = "ffsend-api"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1873,7 +1873,7 @@ dependencies = [
 "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
 "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
 "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
-"checksum ffsend-api 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "976d4238b2ebb0111eb7a14379280ce74c2c50d5d535cb74712ecc6739c51a1f"
+"checksum ffsend-api 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796506969efa8e97ca09320d9e6933ac1b40ee98276db29d29a9a638174e701a"
 "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646"
 "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
 "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"

+ 1 - 1
Cargo.toml

@@ -68,7 +68,7 @@ colored = "1.6"
 derive_builder = "0.7"
 directories = "1.0"
 failure = "0.1"
-ffsend-api = "0.1.0"
+ffsend-api = "0.1.1"
 fs2 = "0.4"
 lazy_static = "1.0"
 open = "1"

+ 6 - 1
src/action/download.rs

@@ -142,8 +142,13 @@ impl<'a> Download<'a> {
         let progress_reader: Arc<Mutex<ProgressReporter>> = progress_bar;
 
         // Execute an download action
+        let progress = if !matcher_main.quiet() {
+            Some(&progress_reader)
+        } else {
+            None
+        };
         ApiDownload::new(&file, target, password, false, Some(metadata))
-            .invoke(&client, &progress_reader)?;
+            .invoke(&client, progress)?;
 
         // Extract the downloaded file if working with an archive
         #[cfg(feature = "archive")]

+ 30 - 20
src/action/upload.rs

@@ -197,31 +197,41 @@ impl<'a> Upload<'a> {
         let (password, password_generated) =
             password.map(|(p, g)| (Some(p), g)).unwrap_or((None, false));
 
-        // Execute an upload action
+        // Execute an upload action, obtain the URL
+        let reporter = if !matcher_main.quiet() {
+            Some(&progress_reporter)
+        } else {
+            None
+        };
         let file = ApiUpload::new(host, path.clone(), file_name, password.clone(), params)
-            .invoke(&client, &progress_reporter)?;
-
-        // Get the download URL, and report it in the console in a table
+            .invoke(&client, reporter)?;
         let url = file.download_url(true);
-        let mut table = Table::new();
-        table.set_format(FormatBuilder::new().padding(0, 2).build());
-        table.add_row(Row::new(vec![
-            Cell::new("Share link:"),
-            Cell::new(url.as_str()),
-        ]));
-        if password_generated {
-            table.add_row(Row::new(vec![
-                Cell::new("Passphrase:"),
-                Cell::new(&password.unwrap_or("?".into())),
-            ]));
-        }
-        if matcher_main.verbose() {
+
+        // Report the result
+        if !matcher_main.quiet() {
+            // Show a table
+            let mut table = Table::new();
+            table.set_format(FormatBuilder::new().padding(0, 2).build());
             table.add_row(Row::new(vec![
-                Cell::new("Owner token:"),
-                Cell::new(file.owner_token().unwrap()),
+                Cell::new("Share link:"),
+                Cell::new(url.as_str()),
             ]));
+            if password_generated {
+                table.add_row(Row::new(vec![
+                    Cell::new("Passphrase:"),
+                    Cell::new(&password.unwrap_or("?".into())),
+                ]));
+            }
+            if matcher_main.verbose() {
+                table.add_row(Row::new(vec![
+                    Cell::new("Owner token:"),
+                    Cell::new(file.owner_token().unwrap()),
+                ]));
+            }
+            table.printstd();
+        } else {
+            println!("{}", url);
         }
-        table.printstd();
 
         // Add the file to the history manager
         #[cfg(feature = "history")]