Skip to content

Commit 8b6a7f2

Browse files
committed
add workspace test for custom BASHLY_LIB_DIR
1 parent 4eea1f2 commit 8b6a7f2

File tree

14 files changed

+146
-3
lines changed

14 files changed

+146
-3
lines changed

lib/bashly/libraries/completions_function.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CompletionsFunction < Completions
44
def files
55
[
66
{
7-
path: "#{Settings.source_dir}/#{Settings.lib_dir}/#{function_name}.sh",
7+
path: "#{Settings.full_lib_dir}/#{function_name}.sh",
88
content: completions_function_code(function_name)
99
}
1010
]

lib/bashly/library.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def target_file_args
6060
{
6161
user_source_dir: Settings.source_dir,
6262
user_target_dir: Settings.target_dir,
63-
user_lib_dir: "#{Settings.source_dir}/#{Settings.lib_dir}",
63+
user_lib_dir: Settings.full_lib_dir,
6464
}
6565
end
6666
end

lib/bashly/script/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def usage_string
125125
# This is meant to provide the user with the ability to add custom
126126
# functions
127127
def user_lib
128-
@user_lib ||= Dir["#{Settings.source_dir}/#{Settings.lib_dir}/**/*.sh"].sort
128+
@user_lib ||= Dir["#{Settings.full_lib_dir}/**/*.sh"].sort
129129
end
130130

131131
# Raise an exception if there are some serious issues with the command

lib/bashly/settings.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def lib_dir
1818
def strict
1919
@strict ||= ENV['BASHLY_STRICT']
2020
end
21+
22+
def full_lib_dir
23+
"#{source_dir}/#{lib_dir}"
24+
end
2125
end
2226
end
2327
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
skipped src/initialize.sh (exists)
4+
skipped src/root_command.sh (exists)
5+
created ./cli
6+
run ./cli --help to test your bash script
7+
+ bundle exec bashly add lib
8+
created src/my-libz/sample_function.sh
9+
+ bundle exec bashly add colors
10+
created src/my-libz/colors.sh
11+
+ bundle exec bashly generate
12+
creating user files in src
13+
skipped src/initialize.sh (exists)
14+
skipped src/root_command.sh (exists)
15+
created ./cli
16+
run ./cli --help to test your bash script
17+
+ ./cli
18+
it works
19+
+ bundle exec bashly generate --upgrade
20+
creating user files in src
21+
skipped src/initialize.sh (exists)
22+
skipped src/root_command.sh (exists)
23+
updated src/my-libz/colors.sh
24+
created ./cli
25+
run ./cli --help to test your bash script
26+
+ bundle exec bashly add comp function
27+
created src/my-libz/send_completions.sh
28+
29+
In order to enable completions in your script, create a command or a flag (for example: cli completions or cli --completions) that calls the send_completions function.
30+
31+
Your users can then run something like this to enable completions:
32+
33+
$ eval "$(cli completions)"
34+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cli
2+
src/lib
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This fixture workspace is used for testing custom BASHLY_LIB_DIR.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: cli
2+
help: Sample application
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Code here runs inside the initialize() function
2+
## Use it for anything that you need to run before any other function, like
3+
## setting environment vairables:
4+
## CONFIG_FILE=settings.ini
5+
##
6+
## Feel free to empty (but not delete) this file.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Color functions [@bashly-upgrade colors]
2+
## This file is a part of Bashly standard library
3+
##
4+
## Usage:
5+
## Use any of the functions below to color or format a portion of a string.
6+
##
7+
## echo "before $(red this is red) after"
8+
## echo "before $(green_bold this is green_bold) after"
9+
##
10+
## Color output will be disabled if `NO_COLOR` environment variable is set
11+
## in compliance with https://no-color.org/
12+
##
13+
print_in_color() {
14+
local color="$1"
15+
shift
16+
if [[ -z ${NO_COLOR+x} ]]; then
17+
printf "$color%b\e[0m\n" "$*";
18+
else
19+
printf "%b\n" "$*";
20+
fi
21+
}
22+
23+
red() { print_in_color "\e[31m" "$*"; }
24+
green() { print_in_color "\e[32m" "$*"; }
25+
yellow() { print_in_color "\e[33m" "$*"; }
26+
blue() { print_in_color "\e[34m" "$*"; }
27+
magenta() { print_in_color "\e[35m" "$*"; }
28+
cyan() { print_in_color "\e[36m" "$*"; }
29+
bold() { print_in_color "\e[1m" "$*"; }
30+
underlined() { print_in_color "\e[4m" "$*"; }
31+
red_bold() { print_in_color "\e[1;31m" "$*"; }
32+
green_bold() { print_in_color "\e[1;32m" "$*"; }
33+
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
34+
blue_bold() { print_in_color "\e[1;34m" "$*"; }
35+
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
36+
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
37+
red_underlined() { print_in_color "\e[4;31m" "$*"; }
38+
green_underlined() { print_in_color "\e[4;32m" "$*"; }
39+
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
40+
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
41+
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
42+
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }

0 commit comments

Comments
 (0)