led_ctrl: run help after parsing of all arguments
authorThomas Monjalon <thomas@monjalon.net>
Mon, 8 Nov 2010 10:53:09 +0000 (11:53 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 8 Nov 2010 13:06:06 +0000 (14:06 +0100)
Allow to interpret $CONFILE according to -c option in help text.

led_ctrl/led_ctrl

index a0c6e3b..3c5a237 100755 (executable)
@@ -4,6 +4,7 @@ SYSPATH=/sys/class/leds
 CONFILE=/etc/led_ctrl.conf
 DEBUG=false
 TESTS=false
+HELP=false
 unset MODE
 
 log_and_exec()
@@ -180,8 +181,7 @@ while [ $# -gt 0 ]; do
                TESTS=true
                ;;
          --help|-h)
-               usage
-               exit 0
+               HELP=true
                ;;
          -*)
                log_and_die "unknown argument: $1\n\n$(usage)"
@@ -193,7 +193,9 @@ while [ $# -gt 0 ]; do
        shift
 done
 
-$TESTS && { run_test_suite; exit $?; }
+$HELP && usage
+$TESTS && run_test_suite
+{ $HELP || $TESTS ;} && exit 0
 
 [ -n "$(ls -A $SYSPATH 2>/dev/null)" ] || \
        log_and_die "missing or empty sysfs LED directory: $SYSPATH"