Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Stack Trace Example

Demonstrates how to show stack trace on error.

This example was generated with:

$ bashly init --minimal
$ bashly add stacktrace
$ bashly generate
# ... now create and edit src/initialize.sh to match the example ...
# ... now edit src/root_command.sh to match the example ...
$ bashly generate

bashly.yml

name: download
help: Sample minimal application without commands
version: 0.1.0

args:
- name: source
  required: true
  help: URL to download from
- name: target
  help: "Target filename (default: same as source)"

flags:
- long: --force
  short: -f
  help: Overwrite existing files

examples:
- download example.com
- download example.com ./output -f

src/initialize.sh

## initialize hook
##
## Any code here will be placed inside the `initialize()` function and called
## before running anything else.
##
## You can safely delete this file if you do not need it.
trap 'stacktrace' ERR
set -o errtrace

src/root_command.sh

## trigger an error by calling a function that does not exist
no_such_command

Output

$ ./download

missing required argument: SOURCE
usage: download SOURCE [TARGET] [OPTIONS]

$ ./download --help

download - Sample minimal application without commands

Usage:
  download SOURCE [TARGET] [OPTIONS]
  download --help | -h
  download --version | -v

Options:
  --force, -f
    Overwrite existing files

  --help, -h
    Show this help

  --version, -v
    Show version number

Arguments:
  SOURCE
    URL to download from

  TARGET
    Target filename (default: same as source)

Examples:
  download example.com
  download example.com ./output -f


$ ./download something

./download: line 15: no_such_command: command not found
./download:15 in `root_command`: no_such_command

Stack trace:
	from ./download:15 in `root_command`
	from ./download:254 in `run`
	from ./download:260 in `main`