From ee36b346d33f4c626e18349fc0849bc77264747a Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Thu, 20 Jan 2022 18:05:03 +0100 Subject: [PATCH] add throw example --- README.org | 45 +++++++++++++++++++++++++++++++++++++++++++++ examples/throw | 19 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 examples/throw diff --git a/README.org b/README.org index dceeaa1..0652d14 100644 --- a/README.org +++ b/README.org @@ -398,3 +398,48 @@ Is 75 really your age? [y/N] y Great! #+end_example + +*** Throw + + This example shows the usage of =sfdeps=: + + #+begin_src sh + #!/usr/bin/env bash + + # ---------------------- + # sf -- script framework + # ---------------------- + + # Declare sf variables + sfdesc="A script that shows the usage of 'sfdeps'. It should always throw an error." + + sfdeps=("source" "nonexistent" "alsononexistent" "echo") + + # Include sf, this could be replaced with a long oneliner + source "$(dirname $0)/sf" + + # ---------------------- + # Actual script + # ---------------------- + + echo "If you see this, the commands 'source', 'nonexistent', 'alsononexistent' and 'echo' are available." + #+end_src + + The usage output: + + #+begin_example + Usage: throw [OPTIONS] + + A script that shows the usage of 'sfdeps'. It should always throw an error. + + OPTIONS + -h, --help Show this help message and exit + #+end_example + + And the execution: + + #+begin_example + $ ./throw + ERROR Command nonexistent not found + ERROR Command alsononexistent not found + #+end_example diff --git a/examples/throw b/examples/throw new file mode 100755 index 0000000..2e64694 --- /dev/null +++ b/examples/throw @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# ---------------------- +# sf -- script framework +# ---------------------- + +# Declare sf variables +sfdesc="A script that shows the usage of 'sfdeps'. It should always throw an error." + +sfdeps=("source" "nonexistent" "alsononexistent" "echo") + +# Include sf, this could be replaced with a long oneliner +source "$(dirname $0)/../sf" + +# ---------------------- +# Actual script +# ---------------------- + +echo "If you see this, the commands 'source', 'nonexistent', 'alsononexistent' and 'echo' are available."