[giggle] Give CLI options higher priority than environment variables



commit 2a4007532717c1b4784e98834dfc483c5466e540
Author: Florian Müllner <fmuellner src gnome org>
Date:   Sun Jan 24 20:24:33 2010 +0100

    Give CLI options higher priority than environment variables
    
    Change the evaluation order for the directory parameter from
    environment -> cli -> default to the much more established
    cli -> environment -> default.
    
    While at it, use G_OPTION_REMAINING instead of argv for the
    directory parameter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=608101

 src/giggle-main.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/giggle-main.c b/src/giggle-main.c
index 95db260..f7d16ef 100644
--- a/src/giggle-main.c
+++ b/src/giggle-main.c
@@ -28,6 +28,7 @@
 
 static gboolean diff_window = FALSE;
 static gboolean version = FALSE;
+static gchar **dirs = NULL;
 
 static GOptionEntry options[] = {
 	{ "diff", 'd',
@@ -37,6 +38,9 @@ static GOptionEntry options[] = {
 	{ "version", 'v',
 	  0, G_OPTION_ARG_NONE, &version,
 	  N_("Show version information and exit"), NULL },
+	{ G_OPTION_REMAINING, '\0',
+	  0, G_OPTION_ARG_FILENAME_ARRAY, &dirs,
+	  NULL, N_("[DIRECTORY]") },
 	{ NULL }
 };
 
@@ -60,7 +64,7 @@ main (int    argc,
 	gdk_threads_init ();
 	gdk_threads_enter ();
 
- 	context = g_option_context_new (N_("[DIRECTORY]"));
+	context = g_option_context_new (NULL);
 
 	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
 	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
@@ -101,15 +105,16 @@ main (int    argc,
 	g_set_application_name ("Giggle");
 	window = giggle_window_new ();
 
-	/* parse GIT_DIR into dir and unset it; if empty use the current_wd */
-	dir = g_strdup (g_getenv ("GIT_DIR"));
-
-	if (!dir || !*dir) {
-		g_free (dir);
-
-		if (argc > 1 && *argv[1]) {
-			dir = g_strdup (argv[1]);
-		} else {
+	/* Set dir to:
+	    - the first remaining arg, or
+	    - the value of GIT_DIR, or
+	    - the current working dir */
+	if (dirs && *dirs) {
+		dir = g_strdup (*dirs);
+		g_strfreev (dirs);
+	} else {
+		dir = g_strdup (g_getenv ("GIT_DIR"));
+		if (dir == NULL) {
 			dir = g_get_current_dir ();
 		}
 	}



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