[fractal] fractal-gtk: Use clap to set verbosity for release builds



commit 8995697f54fd906498b6f759b31b7ef83f064a1c
Author: Christopher Davis <brainblasted disroot org>
Date:   Tue Feb 26 12:40:11 2019 -0500

    fractal-gtk: Use clap to set verbosity for release builds
    
    By default, a release build of Fractal will only log errors.
    A debug build will use the max level for development
    purposes.
    
    Running `fractal -v` will get users the same verbosity as
    the debug build. Subsequent `-v`s will use increased
    verbosity that will include extra info from our dependencies.

 Cargo.lock              |  1 +
 fractal-gtk/Cargo.toml  |  1 +
 fractal-gtk/src/main.rs | 18 +++++++++++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index a619d031..c25ded79 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -446,6 +446,7 @@ version = "4.0.0"
 dependencies = [
  "cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "comrak 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml
index ef8f4bbb..426dec12 100644
--- a/fractal-gtk/Cargo.toml
+++ b/fractal-gtk/Cargo.toml
@@ -7,6 +7,7 @@ workspace = "../"
 edition = "2018"
 
 [dependencies]
+clap = "2.32.0"
 comrak = "0.4.0"
 dirs = "1.0.4"
 failure = "0.1.3"
diff --git a/fractal-gtk/src/main.rs b/fractal-gtk/src/main.rs
index f1d48c7d..118a8eb9 100644
--- a/fractal-gtk/src/main.rs
+++ b/fractal-gtk/src/main.rs
@@ -29,7 +29,23 @@ use log::Level;
 use loggerv;
 
 fn main() -> Result<(), Box<dyn Error>> {
-    loggerv::init_with_level(Level::Error).expect("Failed to initialize logger");
+    #[cfg(not(debug_assertions))]
+    {
+        let clap_args = clap::App::new("app")
+            .arg(
+                clap::Arg::with_name("v")
+                    .short("v")
+                    .multiple("true")
+                    .help("Sets the level of verbosity"),
+            )
+            .get_matches();
+
+        loggerv::init_with_level(clap_args.occurrences_of("v"))
+            .expect("Failed to initialize logger");
+    }
+
+    #[cfg(debug_assertions)]
+    loggerv::init_with_level(Level::Info).expect("Failed to initialize logger");
 
     static_resources::init().expect("GResource initialization failed.");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]