diff --git a/docs/index.md b/docs/index.md index 0edb853..e205875 100644 --- a/docs/index.md +++ b/docs/index.md @@ -231,6 +231,43 @@ get:data() { } ``` +#### Integer option + +Integer options can be used to pass numbers to your commands. Things like `--max-retries=5` and `--cluster-size=3` are great examples where you might want to use an integer option. Integer options have a default value of `0` but may be set to any integer value. Passing an integer option will override the default value to the value provided. + +**Example** + +_`// file: get.sh`_ + +```bash +#!/usr/bin/env bash + +# centry.cmd[get:url].option[url]/required=true +# centry.cmd[get:url].option[max-retries]/type=integer +# centry.cmd[get:url].option[max-retries]/default=3 +get:url() { + echo "Calling ${URL:?} a maximum of ${MAX_RETRIES:?} time(s)" + echo + + local success=false + local attempts=0 + until [[ ${success:?} == true ]]; do + ((attempts++)) + + if ! curl "${URL:?}"; then + if [[ ${attempts:?} -ge ${MAX_RETRIES:?} ]]; then + echo + echo "Max retries reached... exiting!" + return 1 + fi + sleep 1 + else + success=true + fi + done +} +``` + **Usage**: `--` or `--=` #### Select option diff --git a/examples/centry/commands/get.sh b/examples/centry/commands/get.sh index 2839956..5fec6a0 100644 --- a/examples/centry/commands/get.sh +++ b/examples/centry/commands/get.sh @@ -54,3 +54,28 @@ get:required() { get:selected() { echo "The selected value was ${SELECTED:?}" } + +# centry.cmd[get:url].option[url]/required=true +# centry.cmd[get:url].option[max-retries]/type=integer +# centry.cmd[get:url].option[max-retries]/default=3 +get:url() { + echo "Calling ${URL:?} a maximum of ${MAX_RETRIES:?} time(s)" + echo + + local success=false + local attempts=0 + until [[ ${success:?} == true ]]; do + ((attempts++)) + + if ! curl "${URL:?}"; then + if [[ ${attempts:?} -ge ${MAX_RETRIES:?} ]]; then + echo + echo "Max retries reached... exiting!" + return 1 + fi + sleep 1 + else + success=true + fi + done +}