[fractal/fractal-args: 2/2] gtk: Manage all app arguments wiht clap



commit 2697e84a846ab9fb91ca24693b80810a2a2796fa
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Wed Jun 24 13:23:44 2020 +0200

    gtk: Manage all app arguments wiht clap
    
    This patch enables the clap arguments for all compilations, debug or
    production.
    
    We're managing options with clap so we shouldn't pass the arguments to
    the appliation to avoid problems with arguments managed by clap, for
    example for calls with -vv, that's an unknown option for the
    gio::Application.
    
    Fix https://gitlab.gnome.org/GNOME/fractal/-/issues/639

 fractal-gtk/src/main.rs | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
---
diff --git a/fractal-gtk/src/main.rs b/fractal-gtk/src/main.rs
index ccc7307a..bbc896de 100644
--- a/fractal-gtk/src/main.rs
+++ b/fractal-gtk/src/main.rs
@@ -19,7 +19,6 @@ mod widgets;
 
 mod appop;
 
-use std::env::args;
 use std::error::Error;
 
 use crate::app::App;
@@ -30,25 +29,26 @@ use gio::ApplicationExt;
 use log::Level;
 
 fn main() -> Result<(), Box<dyn Error>> {
-    #[cfg(not(debug_assertions))]
-    {
-        let clap_args = clap::App::new("fractal")
-            .version(env!("CARGO_PKG_VERSION"))
-            .about("Matrix group messaging app")
-            .arg(
-                clap::Arg::with_name("v")
-                    .short("v")
-                    .multiple(true)
-                    .help("Sets the level of verbosity"),
-            )
-            .get_matches();
+    let clap_app = clap::App::new("fractal")
+        .version(env!("CARGO_PKG_VERSION"))
+        .about("Matrix group messaging app")
+        .arg(
+            clap::Arg::with_name("v")
+                .short("v")
+                .multiple(true)
+                .help("Sets the level of verbosity"),
+        );
 
-        loggerv::init_with_verbosity(clap_args.occurrences_of("v"))
-            .expect("Failed to initialize logger");
-    }
+    let clap_args = clap_app.get_matches();
+    loggerv::init_with_verbosity(clap_args.occurrences_of("v"))
+        .expect("Failed to initialize logger");
 
     #[cfg(debug_assertions)]
-    loggerv::init_with_level(Level::Info).expect("Failed to initialize logger");
+    {
+        if clap_args.occurrences_of("v") == 0 {
+            loggerv::init_with_level(Level::Info).expect("Failed to initialize logger");
+        }
+    }
 
     static_resources::init().expect("GResource initialization failed.");
 
@@ -64,7 +64,7 @@ fn main() -> Result<(), Box<dyn Error>> {
         App::on_startup(application);
     });
 
-    application.run(&args().collect::<Vec<_>>());
+    application.run(&[]);
 
     Ok(())
 }


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