Skip to content

Commit afdbe52

Browse files
committed
shfmt
1 parent 9d5354b commit afdbe52

File tree

6 files changed

+49
-48
lines changed

6 files changed

+49
-48
lines changed

bin/nodenv-default-packages

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ fi
3232

3333
versions() {
3434
case "$1" in
35-
"") nodenv-version-name ;; # list active version
36-
--all) nodenv-versions --skip-aliases --bare ;; # list all installed versions
37-
*) echo "$@" ;; # list specified versions
35+
"") nodenv-version-name ;; # list active version
36+
--all) nodenv-versions --skip-aliases --bare ;; # list all installed versions
37+
*) echo "$@" ;; # list specified versions
3838
esac
3939
}
4040

@@ -50,23 +50,23 @@ for_versions() {
5050
# Read package names and versions from $NODENV_ROOT/default-packages
5151
list_default_packages() {
5252
default_packages_files |
53-
tr '\n' '\0' | # replace newlines with nullchar so we can use xargs
54-
xargs -0 sed -e 's/#.*$//g' -e '/^[[:space:]]*$/d' | # strip comments and empty lines
55-
while IFS=" " read -r pkg_name pkg_version; do
56-
# shellcheck disable=SC2016
57-
echo "${pkg_name}${pkg_version:+@'$pkg_version'}"
58-
done
53+
tr '\n' '\0' | # replace newlines with nullchar so we can use xargs
54+
xargs -0 sed -e 's/#.*$//g' -e '/^[[:space:]]*$/d' | # strip comments and empty lines
55+
while IFS=" " read -r pkg_name pkg_version; do
56+
# shellcheck disable=SC2016
57+
echo "${pkg_name}${pkg_version:+@'$pkg_version'}"
58+
done
5959
}
6060

6161
install_default_packages() {
6262
list_default_packages |
63-
NODENV_VERSION="$1" xargs nodenv-exec npm install -g
63+
NODENV_VERSION="$1" xargs nodenv-exec npm install -g
6464
}
6565

6666
default_packages_files() {
6767
local file_found
6868

69-
IFS=: read -ra xdg_dirs <<< "${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}"
69+
IFS=: read -ra xdg_dirs <<<"${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}"
7070

7171
for dir in "$NODENV_ROOT" "${xdg_dirs[@]/%//nodenv}"; do
7272
if test -r "$dir/default-packages"; then
@@ -83,13 +83,16 @@ default_packages_files() {
8383
unset cmd
8484

8585
case "$1" in
86-
install ) for_versions install_default_packages "${@:2}" ;;
86+
install) for_versions install_default_packages "${@:2}" ;;
8787

88-
list ) list_default_packages ;;
88+
list) list_default_packages ;;
8989

90-
files ) default_packages_files ;;
90+
files) default_packages_files ;;
9191

92-
-h | --help ) nodenv-help ;;
92+
-h | --help) nodenv-help ;;
9393

94-
*) nodenv-help --usage default-packages; exit 1 ;;
94+
*)
95+
nodenv-help --usage default-packages
96+
exit 1
97+
;;
9598
esac

test/bin/nodenv-install

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ else
3030
fi
3131

3232
case "$1" in
33-
*[0-9].*)
34-
STATUS=0
35-
VERSION_NAME=$1
36-
d="$NODENV_ROOT/versions/$VERSION_NAME"
37-
mkdir -p "$d/bin"
38-
echo "echo \"npm invoked with: \$@\"" > "$d/bin/npm"
39-
chmod a+x "$d/bin/npm"
40-
echo "Installed fake node into $d"
41-
;;
42-
--fail)
43-
STATUS=1
44-
VERSION_NAME=$2
45-
echo "Failed installation of $2"
46-
;;
47-
*)
48-
nodenv-help --usage install >&2
49-
exit 1
50-
;;
33+
*[0-9].*)
34+
STATUS=0
35+
VERSION_NAME=$1
36+
d="$NODENV_ROOT/versions/$VERSION_NAME"
37+
mkdir -p "$d/bin"
38+
echo "echo \"npm invoked with: \$@\"" >"$d/bin/npm"
39+
chmod a+x "$d/bin/npm"
40+
echo "Installed fake node into $d"
41+
;;
42+
--fail)
43+
STATUS=1
44+
VERSION_NAME=$2
45+
echo "Failed installation of $2"
46+
;;
47+
*)
48+
nodenv-help --usage install >&2
49+
exit 1
50+
;;
5151
esac
5252

5353
if [ -z "$skip_hooks" ]; then

test/hook.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load test_helper
44

55
@test "nodenv-install hook auto installs packages" {
6-
with_file "$NODENV_ROOT/default-packages" <<< fake-package
6+
with_file "$NODENV_ROOT/default-packages" <<<fake-package
77

88
run nodenv install 0.10.36
99

test/install.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load test_helper
1111

1212
@test "install, without a version, installs to current node version" {
1313
nodenv install --no-hooks 10.0.0
14-
with_file "$NODENV_ROOT/default-packages" <<< fake-package
14+
with_file "$NODENV_ROOT/default-packages" <<<fake-package
1515

1616
NODENV_VERSION=10.0.0 run nodenv default-packages install
1717

@@ -21,7 +21,7 @@ load test_helper
2121

2222
@test "install accepts node version to which to install" {
2323
nodenv install --no-hooks 10.0.0
24-
with_file "$NODENV_ROOT/default-packages" <<< fake-package
24+
with_file "$NODENV_ROOT/default-packages" <<<fake-package
2525

2626
run nodenv default-packages install 10.0.0
2727

@@ -31,7 +31,7 @@ load test_helper
3131

3232
@test "install npm-installs single package" {
3333
nodenv install --no-hooks 10.0.0
34-
with_file "$NODENV_ROOT/default-packages" <<< fake-package
34+
with_file "$NODENV_ROOT/default-packages" <<<fake-package
3535

3636
run nodenv default-packages install 10.0.0
3737

test/list.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ load test_helper
1010
}
1111

1212
@test "list default-packages" {
13-
with_file "$NODENV_ROOT/default-packages" <<< fake-package
13+
with_file "$NODENV_ROOT/default-packages" <<<fake-package
1414

1515
run nodenv default-packages list
1616

@@ -75,10 +75,10 @@ OUT
7575
}
7676

7777
@test "list combines all default-packages files" {
78-
with_file "$NODENV_ROOT/default-packages" <<< pkg-from-nodenv-root
79-
with_file "$HOME/.config/nodenv/default-packages" <<< pkg-from-config-home
80-
with_file "$HOME/myconfig/nodenv/default-packages" <<< pkg-from-config-dirs1
81-
with_file "$HOME/theirconfig/nodenv/default-packages" <<< pkg-from-config-dirs2
78+
with_file "$NODENV_ROOT/default-packages" <<<pkg-from-nodenv-root
79+
with_file "$HOME/.config/nodenv/default-packages" <<<pkg-from-config-home
80+
with_file "$HOME/myconfig/nodenv/default-packages" <<<pkg-from-config-dirs1
81+
with_file "$HOME/theirconfig/nodenv/default-packages" <<<pkg-from-config-dirs2
8282

8383
XDG_CONFIG_DIRS="$HOME/myconfig:$HOME/theirconfig" run nodenv default-packages list
8484

@@ -92,8 +92,8 @@ OUT
9292
}
9393

9494
@test "list handles filenames with spaces" {
95-
with_file "$HOME/my config/nodenv/default-packages" <<< pkg-from-config-dirs1
96-
with_file "$HOME/their config/nodenv/default-packages" <<< pkg-from-config-dirs2
95+
with_file "$HOME/my config/nodenv/default-packages" <<<pkg-from-config-dirs1
96+
with_file "$HOME/their config/nodenv/default-packages" <<<pkg-from-config-dirs2
9797

9898
XDG_CONFIG_DIRS="$HOME/my config:$HOME/their config" run nodenv default-packages list
9999

test/test_helper.bash

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ setup() {
2626
local core_path="/usr/bin:/bin:/usr/sbin:/sbin"
2727
export PATH="$BATS_MOCK_BINDIR:$test_bin:$package_bin:$node_modules_bin:$core_path"
2828

29-
30-
3129
# custom setup
3230

3331
mkdir -p "$BATS_TMPDIR"
@@ -48,5 +46,5 @@ teardown() {
4846

4947
with_file() {
5048
mkdir -p "$(dirname "$1")"
51-
cat - > "$1"
49+
cat - >"$1"
5250
}

0 commit comments

Comments
 (0)