Skip to content

Commit 74884ec

Browse files
committed
fix: Formatting of printed errors and help menus
1 parent 696517b commit 74884ec

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

pkg/lib/cmd/basalt-package-init.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ EOF
3434
if [ -L "$__basalt_file" ]; then
3535
local __basalt_target="$(readlink "$__basalt_file")"
3636
if ! cd "${__basalt_target%/*}"; then
37-
printf '%s\n' "Error: basalt-package-init: Could not cd to '${__basalt_target%/*}'"
37+
printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_target%/*}'"
3838
return 1
3939
fi
4040
else
4141
if ! cd "${__basalt_file%/*}"; then
42-
printf '%s\n' "Error: basalt-package-init: Could not cd to '${__basalt_file%/*}'"
42+
printf '%s\n' "Error: basalt.package-init: Could not cd to '${__basalt_file%/*}'"
4343
return 1
4444
fi
4545
fi
@@ -57,16 +57,16 @@ EOF
5757
5858
printf '%s' "$PWD"
5959
)"; then
60-
printf '%s\n' "Error: basalt-package-init: Could not find basalt.toml"
60+
printf '%s\n' "Error: basalt.package-init: Could not find basalt.toml"
6161
if ! cd "$__old_cd"; then
62-
printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
62+
printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'"
6363
return 1
6464
fi
6565
return 1
6666
fi
6767
6868
if ! cd "$__old_cd"; then
69-
printf '%s\n' "Error: basalt-package-init: Could not cd back to '$__old_cd'"
69+
printf '%s\n' "Error: basalt.package-init: Could not cd back to '$__old_cd'"
7070
return 1
7171
fi
7272
fi

pkg/lib/public/basalt-global.sh

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,23 @@ basalt.load() {
1919
;;
2020
--help|-h)
2121
cat <<-"EOF"
22-
basalt.load Load a particular file
23-
2422
Usage:
25-
basalt-load [flags] <package> [file]
23+
basalt.load [flags] <package> <file>
2624
2725
Flags:
28-
--global
29-
Use packages installed globally, rather than local packages
30-
31-
--dry
32-
Only print what would have been sourced
33-
34-
--help
35-
Print help menu
26+
--global Use global packages rather than local packages
27+
--dry Only print what would have been sourced
28+
--help Print help
3629
3730
Example:
38-
basalt-load --global 'github.com/rupa/z' 'z.sh'
39-
basalt-load --dry 'github.com/hyperupcall/bats-common-utils' 'load.bash'
40-
basalt-load 'github.com/bats-core/bats-assert' 'load.bash'
31+
basalt.load --global 'github.com/rupa/z' 'z.sh'
32+
basalt.load --dry 'github.com/hyperupcall/bats-common-utils' 'load.bash'
33+
basalt.load 'github.com/bats-core/bats-assert' 'load.bash'
4134
EOF
4235
return
4336
;;
4437
-*)
45-
printf '%s\n' "Error: basalt.load Flag '$arg' not recognized"
38+
printf '%s\n' "Error: basalt.load: Flag '$arg' not recognized"
4639
return 1
4740
;;
4841
esac done
@@ -51,7 +44,7 @@ basalt.load() {
5144
local __basalt_file="${2:-}"
5245

5346
if [ -z "$__basalt_pkg_path" ]; then
54-
printf '%s\n' "Error: basalt.load Missing package as first parameter"
47+
printf '%s\n' "Error: basalt.load: Missing package as first parameter"
5548
return 1
5649
fi
5750

@@ -86,9 +79,9 @@ basalt.load() {
8679
if [ -z "$__basalt_pkg_path_full" ] || [ ! -d "$__basalt_pkg_path_full" ]; then
8780
local __basalt_str='locally'
8881
if [ "$__basalt_flag_global" = 'yes' ]; then
89-
__basalt_str=" globally"
82+
__basalt_str="globally"
9083
fi
91-
printf '%s\n' "Error: basalt.load: Package '$__basalt_pkg_path' is not installed$__basalt_str"
84+
printf '%s\n' "Error: basalt.load: Package '$__basalt_pkg_path' is not installed $__basalt_str"
9285

9386
return 1
9487
fi

pkg/lib/public/basalt-package.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ basalt.package-load() {
77
local __basalt_shopt_nullglob=
88

99
if [ -z "${BASALT_PACKAGE_DIR:-}" ]; then
10-
printf '%s\n' "Error: basalt.package-load: Variable 'BASALT_PACKAGE_DIR' is empty"
10+
printf '%s\n' "Error: basalt.package-load: Variable '\$BASALT_PACKAGE_DIR' is empty"
1111
return 1
1212
fi
1313

@@ -31,7 +31,11 @@ basalt.package-load() {
3131
fi
3232

3333
if [ -f "$__basalt_package.basalt/generated/source_package.sh" ]; then
34-
source "$__basalt_package.basalt/generated/source_package.sh"
34+
if ! source "$__basalt_package.basalt/generated/source_package.sh"; then
35+
:
36+
else
37+
return $?
38+
fi
3539
fi
3640

3741
shopt -s nullglob

pkg/lib/util/util.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ util.init_global() {
4747
touch "$BASALT_GLOBAL_DATA_DIR/global/dependencies"
4848
fi
4949

50-
# Note that I would prefer to check the existence of the target directory as well, but that would mean if the user installs
50+
# I would prefer to check the existence of the target directory as well, but that would mean if the user installs
5151
# a package that creates for example a 'completion' directory, it would not show up until 'basalt' is executed again
5252
if [ ! -L "$BASALT_GLOBAL_DATA_DIR/global/bin" ]; then
5353
ln -sf "$BASALT_GLOBAL_DATA_DIR/global/.basalt/packages/bin" "$BASALT_GLOBAL_DATA_DIR/global/bin"
@@ -333,9 +333,6 @@ util.text_dependency_is_installed() {
333333

334334
util.show_help() {
335335
cat <<"EOF"
336-
Basalt:
337-
The rock-solid Bash package manager
338-
339336
Usage:
340337
basalt [--help|--version]
341338
basalt <local-subcommand> [args...]

0 commit comments

Comments
 (0)