|
| 1 | +# Stack Trace Example |
| 2 | + |
| 3 | +Demonstrates how to show stack trace on error. |
| 4 | + |
| 5 | +This example was generated with: |
| 6 | + |
| 7 | +```bash |
| 8 | +$ bashly init --minimal |
| 9 | +$ bashly add stacktrace |
| 10 | +$ bashly generate |
| 11 | +# ... now create and edit src/initialize.sh to match the example ... |
| 12 | +# ... now edit src/root_command.sh to match the example ... |
| 13 | +$ bashly generate |
| 14 | +``` |
| 15 | + |
| 16 | +<!-- include: src/initialize.sh --> |
| 17 | +<!-- include: src/root_command.sh --> |
| 18 | + |
| 19 | +----- |
| 20 | + |
| 21 | +## `bashly.yml` |
| 22 | + |
| 23 | +````yaml |
| 24 | +name: download |
| 25 | +help: Sample minimal application without commands |
| 26 | +version: 0.1.0 |
| 27 | + |
| 28 | +args: |
| 29 | +- name: source |
| 30 | + required: true |
| 31 | + help: URL to download from |
| 32 | +- name: target |
| 33 | + help: "Target filename (default: same as source)" |
| 34 | + |
| 35 | +flags: |
| 36 | +- long: --force |
| 37 | + short: -f |
| 38 | + help: Overwrite existing files |
| 39 | + |
| 40 | +examples: |
| 41 | +- download example.com |
| 42 | +- download example.com ./output -f |
| 43 | +```` |
| 44 | + |
| 45 | +## `src/initialize.sh` |
| 46 | + |
| 47 | +````bash |
| 48 | +## initialize hook |
| 49 | +## |
| 50 | +## Any code here will be placed inside the `initialize()` function and called |
| 51 | +## before running anything else. |
| 52 | +## |
| 53 | +## You can safely delete this file if you do not need it. |
| 54 | +trap 'stacktrace' ERR |
| 55 | +set -o errtrace |
| 56 | + |
| 57 | +```` |
| 58 | + |
| 59 | + |
| 60 | +## Output |
| 61 | + |
| 62 | +### `$ ./download` |
| 63 | + |
| 64 | +````shell |
| 65 | +missing required argument: SOURCE |
| 66 | +usage: download SOURCE [TARGET] [OPTIONS] |
| 67 | + |
| 68 | + |
| 69 | +```` |
| 70 | + |
| 71 | +### `$ ./download --help` |
| 72 | + |
| 73 | +````shell |
| 74 | +download - Sample minimal application without commands |
| 75 | + |
| 76 | +Usage: |
| 77 | + download SOURCE [TARGET] [OPTIONS] |
| 78 | + download --help | -h |
| 79 | + download --version | -v |
| 80 | + |
| 81 | +Options: |
| 82 | + --force, -f |
| 83 | + Overwrite existing files |
| 84 | + |
| 85 | + --help, -h |
| 86 | + Show this help |
| 87 | + |
| 88 | + --version, -v |
| 89 | + Show version number |
| 90 | + |
| 91 | +Arguments: |
| 92 | + SOURCE |
| 93 | + URL to download from |
| 94 | + |
| 95 | + TARGET |
| 96 | + Target filename (default: same as source) |
| 97 | + |
| 98 | +Examples: |
| 99 | + download example.com |
| 100 | + download example.com ./output -f |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +```` |
| 105 | + |
| 106 | +### `$ ./download something` |
| 107 | + |
| 108 | +````shell |
| 109 | +./download: line 15: no_such_command: command not found |
| 110 | +./download:15 in `root_command`: no_such_command |
| 111 | + |
| 112 | +Stack trace: |
| 113 | + from ./download:15 in `root_command` |
| 114 | + from ./download:254 in `run` |
| 115 | + from ./download:260 in `main` |
| 116 | + |
| 117 | + |
| 118 | +```` |
| 119 | + |
| 120 | + |
| 121 | + |
0 commit comments