[gnome-maps/wip/mlundblad/maps-uri: 1/3] application: Add command line option for search




commit 67bca3ea43d992e5b7ef34edc6f6db9bf13fe21e
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Nov 15 23:21:27 2021 +0100

    application: Add command line option for search
    
    Adds a -S command line option as an alternative
    to initialize a search query. Equivalent to using
    the maps: URI scheme.

 src/application.js | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 7cd11174..aebe721b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -125,6 +125,14 @@ var Application = GObject.registerClass({
                              GLib.OptionArg.NONE,
                              _("Ignore network availability"),
                              null);
+
+        this.add_main_option('search',
+                             'S'.charCodeAt(0),
+                             GLib.OptionFlags.NONE,
+                             GLib.OptionArg.STRING,
+                             _("Search for places"),
+                             null);
+
         /* due to https://gitlab.gnome.org/GNOME/gjs/-/issues/330 the
          * description for the remaining args needs to be passed as both
          * description and arg_description
@@ -425,10 +433,16 @@ var Application = GObject.registerClass({
         }
 
         let remaining = options.lookup(GLib.OPTION_REMAINING, null);
+        let files = [];
 
-        if (remaining) {
-            let files = [];
+        // when given the search CLI argument, insert URI as first file
+        if (options.contains('search')) {
+            let query = options.lookup_value('search', null).deep_unpack();
+
+            files = [Gio.File.new_for_uri(`maps:q=${query}`)];
+        }
 
+        if (remaining) {
             remaining.forEach((r) => {
                 let path = r.get_string()[0];
 
@@ -439,11 +453,12 @@ var Application = GObject.registerClass({
                     files.push(Gio.File.new_for_path(path));
                 }
             });
+        }
 
+        if (files.length > 0)
             this.open(files, '');
-        } else {
+        else
             this.activate();
-        }
 
         return 0;
     }


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