diff --git a/README.md b/README.md index 03b54f0..e5af384 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,9 @@ first. It will never: pullr [options] [DIR] ``` +Short options can be combined: `-rs` is `-r -s`, and `-j8` or `-rj 8` set +the number of jobs. + | Option                       | Default | Meaning | | :--- | :--- | :--- | | `DIR` | current directory | Where to look for repositories | diff --git a/bin/pullr b/bin/pullr index dc6470a..be9a291 100755 --- a/bin/pullr +++ b/bin/pullr @@ -36,6 +36,8 @@ Options: set (https://no-color.org) or output is not a terminal. -V, --version Print the version. -h, --help Show this help. + +Short options can be combined: -rs is -r -s, and -j8 or -rj 8 set the jobs. EOF } @@ -50,6 +52,16 @@ root="" while (($#)); do case "$1" in + # bundled short options: split -rs into -r -s, and -j8 into -j 8 + -[!-]?*) + opt="${1:1:1}" rest="${1:2}" + shift + if [[ "$opt" == j ]]; then + set -- -j "$rest" "$@" + else + set -- "-$opt" "-$rest" "$@" + fi + ;; -j|--jobs) jobs="${2:-}"; shift 2 || { usage >&2; exit 2; } ;; --jobs=*) jobs="${1#*=}"; shift ;; --max-depth) max_depth="${2:-}"; shift 2 || { usage >&2; exit 2; } ;; diff --git a/test/pullr.bats b/test/pullr.bats index 8b35275..5c539e1 100644 --- a/test/pullr.bats +++ b/test/pullr.bats @@ -587,3 +587,28 @@ make_edited() { [ "$status" -eq 0 ] [[ "$output" == *" + app/lib (main, 1 new commit)"* ]] } + +@test "short options combine: -sn, -j8, -snj 1 and -rs" { + make_app_with_submodule + git -C ws/app/lib commit -q --allow-empty -m "my lib work" + advance_lib 2 + run pullr -sn ws + [[ "$output" == "Dry run: nothing will be pulled."* ]] + [[ "$output" == *" x app/lib (main)"* ]] + run pullr -j8 -n ws + [ "$status" -eq 0 ] + run pullr -snj 1 ws + [[ "$output" == *" x app/lib (main)"* ]] + run pullr -rs ws + [ "$status" -eq 0 ] + [[ "$output" == *" + app/lib (main, 1 new commit, 1 rebased)"* ]] + [ "$(git -C ws/app/lib log -1 --format=%s)" = "my lib work" ] +} + +@test "an unknown letter in a bundle is rejected" { + run pullr -rx ws + [ "$status" -eq 2 ] + [[ "$output" == *"Unknown option: -x"* ]] + run pullr -rj + [ "$status" -eq 2 ] +}