diff options
author | Marcus Lundblad <ml@update.uu.se> | 2021-11-15 23:21:27 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2021-11-19 23:18:08 +0100 |
commit | b5e833e9b47ed0146145f9208292ebbf9a95bda5 (patch) | |
tree | 00bf737aa88b97cd2cf853cc19d8cf227a4fa90a | |
parent | d65cf3151dbb4af8e2e33fd8df4d01e3121cde1f (diff) | |
download | gnome-maps-b5e833e9b47ed0146145f9208292ebbf9a95bda5.tar.gz |
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.
-rw-r--r-- | src/application.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/application.js b/src/application.js index ec19318d..07fbb6a1 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; } |