Skip to content

Commit

Permalink
Updated docs for Integer options.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferahl committed Sep 17, 2021
1 parent 043512a commit 48810fe
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**: `--<option_name>` or `--<option_name>=<value>`

#### Select option
Expand Down
25 changes: 25 additions & 0 deletions examples/centry/commands/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 48810fe

Please sign in to comment.