├── Makefile ├── .shellcheckrc ├── test ├── bask.bats ├── version.bats ├── test_helper.bash ├── commands.bats └── help.bats ├── package.json ├── README.md ├── LICENSE └── bask /Makefile: -------------------------------------------------------------------------------- 1 | BIN ?= bask 2 | PREFIX ?= /usr/local 3 | 4 | install: 5 | install $(BIN) $(PREFIX)/bin 6 | 7 | uninstall: 8 | rm -f $(PREFIX)/bin/$(BIN) 9 | -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # .shellcheckrc 3 | # 4 | # https://github.com/koalaman/shellcheck 5 | # https://github.com/koalaman/shellcheck/wiki/Ignore 6 | ############################################################################### 7 | 8 | # Disable SC1090 9 | # 10 | # https://github.com/koalaman/shellcheck/wiki/SC1090 11 | disable=SC1090 12 | -------------------------------------------------------------------------------- /test/bask.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | 5 | @test "'bask' with no arguments exits with 0 and prints default help." { 6 | run "${_BASK}" 7 | 8 | printf "\${status}: '%s'\\n" "${status}" 9 | printf "\${output}: '%s'\\n" "${output}" 10 | 11 | [[ "${status}" -eq 0 ]] 12 | [[ "${output}" =~ Usage:${_NEWLINE}\ \ bask\ \ ]] 13 | } 14 | -------------------------------------------------------------------------------- /test/version.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | 5 | @test "\`bask version\` returns with 0 status." { 6 | run "${_BASK}" --version 7 | [[ "${status}" -eq 0 ]] 8 | } 9 | 10 | @test "\`bask version\` prints a version number." { 11 | run "${_BASK}" --version 12 | printf "'%s'" "${output}" 13 | echo "${output}" | grep -q '\d\+\.\d\+\.\d\+' 14 | } 15 | 16 | @test "\`bask --version\` returns with 0 status." { 17 | run "${_BASK}" --version 18 | [[ "${status}" -eq 0 ]] 19 | } 20 | 21 | @test "\`bask --version\` prints a version number." { 22 | run "${_BASK}" --version 23 | printf "'%s'" "${output}" 24 | echo "${output}" | grep -q '\d\+\.\d\+\.\d\+' 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bask.sh", 3 | "version": "0.5.1", 4 | "description": "An mini-framework for command-centric Bash scripts.", 5 | "global": true, 6 | "install": "make install", 7 | "bin": { 8 | "bask": "./bask" 9 | }, 10 | "directories": { 11 | "test": "test" 12 | }, 13 | "scripts": { 14 | "test": "bats test" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/xwmx/bask.git" 19 | }, 20 | "keywords": [ 21 | "bash", 22 | "task-runner", 23 | "shell", 24 | "command-line", 25 | "cli", 26 | "terminal", 27 | "prompt", 28 | "command" 29 | ], 30 | "author": "William Melody", 31 | "license": "GPL-2.0-only", 32 | "bugs": { 33 | "url": "https://github.com/xwmx/bask/issues" 34 | }, 35 | "homepage": "https://github.com/xwmx/bask#readme", 36 | "dependencies": {} 37 | } 38 | -------------------------------------------------------------------------------- /test/test_helper.bash: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # test_helper.bash 3 | # 4 | # Test helper for Bats: Bash Automated Testing System. 5 | # 6 | # https://github.com/sstephenson/bats 7 | ############################################################################### 8 | 9 | setup() { 10 | # `$_BASK` 11 | # 12 | # The location of the `bask` script being tested. 13 | export _BASK="${BATS_TEST_DIRNAME}/../bask" 14 | 15 | # `$_NEWLINE` 16 | # 17 | # Newline with ANSI-C quoting. 18 | export _NEWLINE=$'\n' 19 | } 20 | 21 | ############################################################################### 22 | # Helpers 23 | ############################################################################### 24 | 25 | # _compare() 26 | # 27 | # Usage: 28 | # _compare 29 | # 30 | # Description: 31 | # Compare the content of a variable against an expected value. When used 32 | # within a `@test` block the output is only displayed when the test fails. 33 | _compare() { 34 | local _expected="${1:-}" 35 | local _actual="${2:-}" 36 | printf "expected:\n%s\n" "${_expected}" 37 | printf "actual:\n%s\n" "${_actual}" 38 | } 39 | -------------------------------------------------------------------------------- /test/commands.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load test_helper 4 | 5 | @test "'bask commands' exits with 0 and prints subcommands." { 6 | run "${_BASK}" commands 7 | 8 | printf "\${status}: '%s'\\n" "${status}" 9 | printf "\${output}: '%s'\\n" "${output}" 10 | 11 | [[ "${status}" -eq 0 ]] 12 | 13 | diff \ 14 | <(printf "%s\\n" "${output}") \ 15 | <(cat < `-a -b -c`) and option parsing, 26 | - Automatic arbitrary command loading, 27 | - A simple approach for specifying per-command help with `describe`, 28 | - Built-in commands for help, version, and command listing, 29 | - Conventions for distinguishing between functions and program commands, 30 | - Useful utility functions. 31 | 32 | ## Installation 33 | 34 | ### Homebrew 35 | 36 | To install with [Homebrew](http://brew.sh/): 37 | 38 | ```bash 39 | brew tap xwmx/taps 40 | brew install bask 41 | ``` 42 | 43 | ### npm 44 | 45 | To install with [npm](https://www.npmjs.com/package/bask.sh): 46 | 47 | ```bash 48 | npm install --global bask.sh 49 | ``` 50 | 51 | ### bpkg 52 | 53 | To install with [bpkg](http://www.bpkg.io/): 54 | 55 | ```bash 56 | bpkg install xwmx/bask 57 | ``` 58 | 59 | ### Manual 60 | 61 | To install manually, simply add the `bask` script to your `$PATH`. If 62 | you already have a `~/bin` directory, you can use the following command: 63 | 64 | ```bash 65 | curl -L https://raw.github.com/xwmx/bask/master/bask \ 66 | -o ~/bin/bask && chmod +x ~/bin/bask 67 | ``` 68 | 69 | ## Usage 70 | 71 | `bask` can be used primarily in two ways: with with scripts that source (or, 72 | in other words, inherit from) the `bask` program, or with Baskfiles defining 73 | functions for the current context. 74 | 75 | ### Bask Scripts 76 | 77 | To generate a new `bask` script, meaning a script that 78 | inherits the `bask` foundation, use add an argument to the `new` 79 | command specifying the script name: 80 | 81 | ```bash 82 | bask new