From f706367983c249e99f0a1fd5b4d212495ff60787 Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.oliveiramaroneze@cea.fr>
Date: Tue, 23 Jul 2019 17:48:18 +0200
Subject: [PATCH] [fc-script] add 'help' command and fix exit code on error

---
 bin/frama-c-script | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/bin/frama-c-script b/bin/frama-c-script
index e3dafca01d8..17c28726207 100755
--- a/bin/frama-c-script
+++ b/bin/frama-c-script
@@ -26,11 +26,14 @@ while [ $# -ge 1 -a "$1" = "-check" ]; do
     shift
 done
 
-if [ $# -lt 1 ]; then
+usage() {
    echo "usage: $0 cmd [args]"
    echo ""
    echo "  where cmd is:"
    echo ""
+   echo "  - help"
+   echo "      Display this help message and exit."
+   echo ""
    echo "  - make-template [dir]"
    echo "      Interactively prepares a template for running analysis scripts,"
    echo "      writing it to [dir/GNUmakefile]. [dir] is [.] if omitted."
@@ -74,7 +77,11 @@ if [ $# -lt 1 ]; then
    echo "  - normalize-jcdb [path/to/compile_commands.json]"
    echo "      Applies some transformations to an existing compile_commands.json"
    echo "      (such as relativizing paths) to improve portability"
-   exit
+   exit $1
+}
+
+if [ $# -lt 1 ]; then
+    usage 1
 fi
 
 DIR="$( cd "$( dirname "$0" )" && pwd )"
@@ -276,6 +283,9 @@ normalize_jcdb() {
 }
 
 case "$command" in
+    "help" | "-help" | "--help" | "-h")
+        usage 0;
+        ;;
     "make-template")
         shift;
         make_template "$@";
@@ -313,5 +323,6 @@ case "$command" in
         normalize_jcdb "$@";
         ;;
     *)
-        echo "error: unrecognized command: $command"
+        echo "error: unrecognized command: $command";
+        exit 1
 esac
-- 
GitLab