Updated coding style

pull/84/head
deajan 8 years ago
parent e4fb2c5938
commit 3c9780c55e

@ -1,4 +1,4 @@
Coding style used for my bash projects (v2.4 Sep 2016)
Coding style used for my bash projects (v2.6 Nov 2016)
++++++ Header
@ -125,14 +125,26 @@ fi
++++++ Logging
A logging function is available with the following levels of logging:
A logging function is available that writes both to log file and stdout/stderr.
It has the following global variable modifiers:
- DEBUG: Only log this when DEBUG flas is set in program. Any command forged for eval instruction should be logged by this.
_LOGGER_SILENT=true/false: disables any output to stdout/stderr
_LOGGER_VERBOSE=true/false: logs messages with log level VERBOSE
_LOGGER_ERR_ONLY=true/false: disables logging to log file and stdout/stderr except for CRITICAL, ERROR, WARN and ALWAYS log levels.
The following log levels exist:
- PARANOIA_DEBUG: Only used by debugging functions themselves
- DEBUG: Only log this when _DEBUG flag is set in program. Any command forged for eval instruction should be logged by this.
- NOTICE: Standard messages
- ALWAYS: Standard messages, regardless of _LOGGER_ERR_ONLY
- WARN: Requires attention
- ERROR: Program produced an error but continues execution
- CRITICAL: Program execution is halted
Can be called with:
Logger "My message" "LOGLEVEL"
++++++ Eval
Most commands should be logged to a tmp file.
@ -151,6 +163,14 @@ cmd=$SSH_CMD' "some; commands \"'$VARIABLE'\" some; other; commands" > some_file
All eval cmd should exit their content to a file called "$RUNDIR/osync.$FUNCNAME.$SCRIPT_PID"
Dots are used instead of '_' so variables can be separated with a forbidden char in variable names, so the separtors apply as wished.
++++++ String function calls
String returning functions should only be called this way in order to deal with spaces:
Quoting happens outside the function call.
echo "$(myStringFunction $myStringVar)"
++++++ Finding code errors
Use shellcheck.net now and then (ignore SC2086 in our case)
@ -183,3 +203,10 @@ Run with errors exit code = 1
Run with warnings exit code = 2
Wrong shell exit code = 127
Usage function exit code = 128
+++++++ Detailled debugging
When launching the program with 'bash -x', add SLEEP_TIME=1 so wait functions won't spam output
Ex:
SLEEP_TIME=1 bash -x ./program.sh

Loading…
Cancel
Save