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.
Marcus Lundblad
2 years ago
124 | 124 | GLib.OptionArg.NONE, |
125 | 125 | _("Ignore network availability"), |
126 | 126 | null); |
127 | ||
128 | this.add_main_option('search', | |
129 | 'S'.charCodeAt(0), | |
130 | GLib.OptionFlags.NONE, | |
131 | GLib.OptionArg.STRING, | |
132 | _("Search for places"), | |
133 | null); | |
134 | ||
127 | 135 | /* due to https://gitlab.gnome.org/GNOME/gjs/-/issues/330 the |
128 | 136 | * description for the remaining args needs to be passed as both |
129 | 137 | * description and arg_description |
424 | 432 | } |
425 | 433 | |
426 | 434 | let remaining = options.lookup(GLib.OPTION_REMAINING, null); |
435 | let files = []; | |
436 | ||
437 | // when given the search CLI argument, insert URI as first file | |
438 | if (options.contains('search')) { | |
439 | let query = options.lookup_value('search', null).deep_unpack(); | |
440 | ||
441 | files = [Gio.File.new_for_uri(`maps:q=${query}`)]; | |
442 | } | |
427 | 443 | |
428 | 444 | if (remaining) { |
429 | let files = []; | |
430 | ||
431 | 445 | remaining.forEach((r) => { |
432 | 446 | let path = r.get_string()[0]; |
433 | 447 | |
438 | 452 | files.push(Gio.File.new_for_path(path)); |
439 | 453 | } |
440 | 454 | }); |
441 | ||
455 | } | |
456 | ||
457 | if (files.length > 0) | |
442 | 458 | this.open(files, ''); |
443 | } else { | |
459 | else | |
444 | 460 | this.activate(); |
445 | } | |
446 | 461 | |
447 | 462 | return 0; |
448 | 463 | } |