Procházet zdrojové kódy

ensure help() is defined before it is called

Pi před 3 roky
rodič
revize
e41eef7e3d
1 změnil soubory, kde provedl 21 přidání a 21 odebrání
  1. 21 21
      grocery_transactions.sh

+ 21 - 21
grocery_transactions.sh

@@ -9,6 +9,27 @@ set -euo pipefail
 ENDKW=ROLLBACK
 DATE="$(date +%Y-%m-%d)"
 STORE=" IS NOT NULL"
+usage(){
+    cat <<EOF
+Usage: ./${0##*/} [ -d DATE ] [ -s STORE ] [ -r | -c ] < transactions.txn
+ 
+Companion script for grocery_transactions.py
+
+Reads transactions from stdin.
+ROLLBACK (-r) is enabled by default
+Date is optional and by default is set to current day.
+Date and store only affect the display of the transactions.
+If store is not set, then all stores are shown for that day.
+
+Example:
+    # load generated transactions with ROLLBACK
+    ./${0##*/} -d DATE -s STORE < transactions.txn
+    ./${0##*/} -d DATE -s STORE -r < transactions.txn
+    
+    # load generated transactions with COMMIT
+    ./${0##*/} -d DATE -s STORE -c < transactions.txn
+EOF
+}
 while getopts ":crd:s:" options; do
   case "${options}" in         
     c)                          
@@ -31,27 +52,6 @@ while getopts ":crd:s:" options; do
   esac
 done
 
-usage(){
-    cat <<EOF
-Usage: ./${0##*/} [ -d DATE ] [ -s STORE ] [ -r | -c ] < transactions.txn
- 
-Companion script for grocery_transactions.py
-
-Reads transactions from stdin.
-ROLLBACK (-r) is enabled by default
-Date is optional and by default is set to current day.
-Date and store only affect the display of the transactions.
-If store is not set, then all stores are shown for that day.
-
-Example:
-    # load generated transactions with ROLLBACK
-    ./${0##*/} -d DATE -s STORE < transactions.txn
-    ./${0##*/} -d DATE -s STORE -r < transactions.txn
-    
-    # load generated transactions with COMMIT
-    ./${0##*/} -d DATE -s STORE -c < transactions.txn
-EOF
-}
 if [[ -t 0 ]]
 then
     usage 1>&2