diff --git a/README.md b/README.md index f90a1a5..ed3f4e6 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ for URL in "${URLS[@]}"; do done ``` -### Command-line flags +### Using command-line flags If a bash script calls another application that accepts command-line flags, use long flag names where available. @@ -162,6 +162,55 @@ Make exceptions for flags where the short flags are extremely common and the lon * `mkdir -p` +### Parsing command-line flags + +In the same way that we prefer to use long flag names, we also prefer to implement long flag names. + +```bash +print_help() { + cat <&2 print_help + exit 1 + esac +done +readonly TARGET_FILE +readonly FORCE + +if [[ -z "${TARGET_FILE}" ]]; then + >&2 echo 'Missing parameter: TARGET_FILE' + >&2 print_help + exit 1 +fi +``` + +There's no need to implement short flag names because our scripts are either being called by other scripts, internally, or users are copy/pasting commands from examples we've given them. Either way, we prefer to see long flag names being used. + ### Error messages * Print error messages to stderr.