everest-dev-docs/docs/coding-style.txt

46 lines
900 B
Plaintext
Raw Permalink Normal View History

2022-11-18 08:09:01 -05:00
Note: this document mainly focuses on shell scripts. For other languages, see the appropriate document.
Everest scripts should follow a relatively similar coding style.
1 - Shebangs
Every script MUST start with a shebang pointing to /bin/sh
#!/bin/sh
2022-12-01 08:29:35 -05:00
This ensures the script is shell-agnostic (unless you're weird and symlinked some POSIX-incompatible shell to /bin/sh)
2022-11-18 08:09:01 -05:00
2 - Functions
Most scripts must be written with functions in mind. This improves code readability and reproducibility.
myfunction() {
printf "hello world\n"
exit 0
}
3 - Output
Scripts that output color MUST call the variable as follows:
${color}
This ensures there are no extra spaces.
All print statements MUST end with a newline ("\n") statement.
4 - Arguments
Arguments should be implemented in the following way:
case $1 in
arg1)
somefunction "$@"
;;
arg2)
somefunction "$@"
;;
esac