[gjs] console: Add --version option
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] console: Add --version option
- Date: Thu, 20 Oct 2016 22:04:31 +0000 (UTC)
commit 0b9f7027cee7f7c9edb668ef62356953609a71bc
Author: Philip Chimento <philip endlessm com>
Date: Wed Oct 19 17:29:50 2016 -0700
console: Add --version option
Now that we can avoid passing --version on to scripts, it is simple to
add a --version option that prints the current GJS version.
https://bugzilla.gnome.org/show_bug.cgi?id=772033
gjs/console.cpp | 8 ++++++++
test/testCommandLine.sh | 13 +++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 917f9fb..f9aff03 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -34,10 +34,12 @@ static char **include_path = NULL;
static char **coverage_prefixes = NULL;
static char *coverage_output_path = NULL;
static char *command = NULL;
+static gboolean print_version = false;
static const char *GJS_COVERAGE_CACHE_FILE_NAME = ".internal-gjs-coverage-cache";
static GOptionEntry entries[] = {
+ { "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print GJS version and exit" },
{ "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Program passed in as a string", "COMMAND" },
{ "coverage-prefix", 'C', 0, G_OPTION_ARG_STRING_ARRAY, &coverage_prefixes, "Add the prefix PREFIX to
the list of files to generate coverage info for", "PREFIX" },
{ "coverage-output", 0, 0, G_OPTION_ARG_STRING, &coverage_output_path, "Write coverage output to a
directory DIR. This option is mandatory when using --coverage-path", "DIR", },
@@ -111,6 +113,7 @@ main(int argc, char **argv)
coverage_prefixes = NULL;
coverage_output_path = NULL;
command = NULL;
+ print_version = false;
g_option_context_set_ignore_unknown_options(context, false);
g_option_context_set_help_enabled(context, true);
if (!g_option_context_parse(context, &gjs_argc, &gjs_argv, &error))
@@ -118,6 +121,11 @@ main(int argc, char **argv)
g_option_context_free (context);
+ if (print_version) {
+ g_print("%s\n", PACKAGE_STRING);
+ exit(0);
+ }
+
if (command != NULL) {
script = command;
len = strlen(script);
diff --git a/test/testCommandLine.sh b/test/testCommandLine.sh
index ddb31ec..417ab16 100755
--- a/test/testCommandLine.sh
+++ b/test/testCommandLine.sh
@@ -61,4 +61,17 @@ if "$gjs" help.js --help -I sentinel; then
fail "-I after script file should not be added to search path"
fi
+# --version works
+"$gjs" --version >/dev/null || \
+ fail "--version should work"
+test -n "`"$gjs" --version`" || \
+ fail "--version should print something"
+
+# --version after a script goes to the script
+script='if(ARGV[0] !== "--version") imports.system.exit(1)'
+"$gjs" -c "$script" --version || \
+ fail "--version after -c should be passed to script"
+test -z "`"$gjs" -c "$script" --version`" || \
+ fail "--version after -c should not print anything"
+
rm -f help.js
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]