bashly 0.6.8 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/bashly/commands/add.rb +18 -6
- data/lib/bashly/concerns/completions.rb +5 -1
- data/lib/bashly/models/base.rb +1 -0
- data/lib/bashly/templates/lib/colors.sh +34 -21
- data/lib/bashly/templates/lib/validations/validate_dir_exists.sh +3 -0
- data/lib/bashly/templates/lib/validations/validate_file_exists.sh +3 -0
- data/lib/bashly/templates/lib/validations/validate_integer.sh +3 -0
- data/lib/bashly/templates/lib/validations/validate_not_empty.sh +3 -0
- data/lib/bashly/templates/strings.yml +1 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/validations.erb +8 -0
- data/lib/bashly/views/command/parse_requirements_case.erb +2 -1
- data/lib/bashly/views/command/required_args_filter.erb +2 -1
- data/lib/bashly/views/flag/case.erb +2 -1
- data/lib/bashly/views/flag/validations.erb +8 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c76c3000789b54fa2d9be8f7a61d93556e6a8665f4ea7769588797a25fa78f49
|
4
|
+
data.tar.gz: a5a0eae36b00cf879082836211f2aa21b38b280993e2dccfc907f3e6fcb99104
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae77cd9b8fa000d9e12f2948fb5c41bd02e34bd6bdcdd91f3a3a627778f66c9472e956e92fb65b502fa78fe2e77ba6c4dfb12c1f35abed36f1012ce502b7cab9
|
7
|
+
data.tar.gz: 5e14659441abf6b11ca53a5d0d656e5097519acc7a2e842f3cdfb6374fd52a0403c6ddeacf4f193da1ab18687de909b074e4d581ce4700c9fc28e2b589ef961d
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ a [docker image](https://hub.docker.com/r/dannyben/bashly).
|
|
40
40
|
file for you ([example](https://github.com/DannyBen/bashly/tree/master/examples/minimal#bashlyyml)).
|
41
41
|
2. Bashly then automatically generates a bash script (when you run
|
42
42
|
`bashly generate`) that can parse and validate user input, provide help
|
43
|
-
messages, and run your code for each command
|
43
|
+
messages, and run your code for each command.
|
44
44
|
3. Your code for each command is kept in a separate file, and can be merged
|
45
45
|
again if you change it ([example](https://github.com/DannyBen/bashly/blob/master/examples/minimal/src/root_command.sh)).
|
46
46
|
|
@@ -67,11 +67,13 @@ Bashly is responsible for:
|
|
67
67
|
## Contributing / Support
|
68
68
|
|
69
69
|
If you experience any issue, have a question or a suggestion, or if you wish
|
70
|
-
to contribute, feel free to [open an issue][issues]
|
70
|
+
to contribute, feel free to [open an issue][issues] or
|
71
|
+
[start a discussion][discussions].
|
71
72
|
|
72
73
|
|
73
74
|
|
74
75
|
[issues]: https://github.com/DannyBen/bashly/issues
|
76
|
+
[discussions]: https://github.com/DannyBen/bashly/discussions
|
75
77
|
[docs]: https://bashly.dannyb.co/
|
76
78
|
[examples]: https://github.com/DannyBen/bashly/tree/master/examples#bashly-examples
|
77
79
|
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -8,6 +8,7 @@ module Bashly
|
|
8
8
|
usage "bashly add config [--force]"
|
9
9
|
usage "bashly add colors [--force]"
|
10
10
|
usage "bashly add yaml [--force]"
|
11
|
+
usage "bashly add validations [--force]"
|
11
12
|
usage "bashly add comp FORMAT [OUTPUT]"
|
12
13
|
usage "bashly add (-h|--help)"
|
13
14
|
|
@@ -21,6 +22,7 @@ module Bashly
|
|
21
22
|
command "config", "Add standard functions for handling INI files to the lib directory."
|
22
23
|
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
23
24
|
command "yaml", "Add standard functions for reading YAML files to the lib directory."
|
25
|
+
command "validations", "Add argument validation functions to the lib directory."
|
24
26
|
command "comp", "Generate a bash completions script or function."
|
25
27
|
|
26
28
|
example "bashly add strings --force"
|
@@ -34,19 +36,23 @@ module Bashly
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def lib_command
|
37
|
-
|
39
|
+
safe_copy_file "sample_function.sh"
|
38
40
|
end
|
39
41
|
|
40
42
|
def config_command
|
41
|
-
|
43
|
+
safe_copy_file "config.sh"
|
42
44
|
end
|
43
45
|
|
44
46
|
def colors_command
|
45
|
-
|
47
|
+
safe_copy_file "colors.sh"
|
46
48
|
end
|
47
49
|
|
48
50
|
def yaml_command
|
49
|
-
|
51
|
+
safe_copy_file "yaml.sh"
|
52
|
+
end
|
53
|
+
|
54
|
+
def validations_command
|
55
|
+
safe_copy_dir "validations"
|
50
56
|
end
|
51
57
|
|
52
58
|
def comp_command
|
@@ -68,8 +74,14 @@ module Bashly
|
|
68
74
|
|
69
75
|
private
|
70
76
|
|
71
|
-
def
|
72
|
-
|
77
|
+
def safe_copy_dir(dir)
|
78
|
+
Dir[asset("templates/lib/#{dir}/*.sh")].sort.each do |file|
|
79
|
+
safe_copy_file "#{dir}/#{File.basename file}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def safe_copy_file(file)
|
84
|
+
safe_copy asset("templates/lib/#{file}"), "#{Settings.source_dir}/lib/#{file}"
|
73
85
|
end
|
74
86
|
|
75
87
|
def safe_copy(source, target)
|
@@ -31,12 +31,16 @@ module Bashly
|
|
31
31
|
flags.map(&:name) + flags.map(&:short)
|
32
32
|
end
|
33
33
|
|
34
|
+
def completion_allowed_args
|
35
|
+
flags.map(&:allowed).flatten + args.map(&:allowed).flatten
|
36
|
+
end
|
37
|
+
|
34
38
|
def completion_words(with_version: false)
|
35
39
|
trivial_flags = %w[--help -h]
|
36
40
|
trivial_flags += %w[--version -v] if with_version
|
37
41
|
all = (
|
38
42
|
command_names + trivial_flags +
|
39
|
-
completion_flag_names
|
43
|
+
completion_flag_names + completion_allowed_args
|
40
44
|
)
|
41
45
|
|
42
46
|
all += completions if completions
|
data/lib/bashly/models/base.rb
CHANGED
@@ -4,29 +4,42 @@
|
|
4
4
|
#
|
5
5
|
# Usage:
|
6
6
|
# Use any of the functions below to color or format a portion of a string.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# echo "before $(red this is red) after"
|
9
9
|
# echo "before $(green_bold this is green_bold) after"
|
10
10
|
#
|
11
|
+
# Color output will be disabled if `NO_COLOR` environment variable is set
|
12
|
+
# in compliance with https://no-color.org/
|
13
|
+
#
|
11
14
|
# ---
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
print_in_color() {
|
17
|
+
local color="$1"
|
18
|
+
shift
|
19
|
+
if [[ -z ${NO_COLOR+x} ]]; then
|
20
|
+
printf "$color%b\e[0m\n" "$*";
|
21
|
+
else
|
22
|
+
printf "%b\n" "$*";
|
23
|
+
fi
|
24
|
+
}
|
25
|
+
|
26
|
+
red() { print_in_color "\e[31m" "$*"; }
|
27
|
+
green() { print_in_color "\e[32m" "$*"; }
|
28
|
+
yellow() { print_in_color "\e[33m" "$*"; }
|
29
|
+
blue() { print_in_color "\e[34m" "$*"; }
|
30
|
+
magenta() { print_in_color "\e[35m" "$*"; }
|
31
|
+
cyan() { print_in_color "\e[36m" "$*"; }
|
32
|
+
bold() { print_in_color "\e[1m" "$*"; }
|
33
|
+
underlined() { print_in_color "\e[4m" "$*"; }
|
34
|
+
red_bold() { print_in_color "\e[1;31m" "$*"; }
|
35
|
+
green_bold() { print_in_color "\e[1;32m" "$*"; }
|
36
|
+
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
|
37
|
+
blue_bold() { print_in_color "\e[1;34m" "$*"; }
|
38
|
+
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
|
39
|
+
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
|
40
|
+
red_underlined() { print_in_color "\e[4;31m" "$*"; }
|
41
|
+
green_underlined() { print_in_color "\e[4;32m" "$*"; }
|
42
|
+
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
|
43
|
+
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
|
44
|
+
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
|
45
|
+
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }
|
@@ -32,3 +32,4 @@ missing_dependency: "missing dependency: %{dependency}"
|
|
32
32
|
disallowed_flag: "%{name} must be one of: %{allowed}"
|
33
33
|
disallowed_argument: "%{name} must be one of: %{allowed}"
|
34
34
|
unsupported_bash_version: "bash version 4 or higher is required"
|
35
|
+
validation_error: "validation error in %s:\\n%s"
|
data/lib/bashly/version.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
% if args.any?
|
3
3
|
% condition = "if"
|
4
4
|
% args.each do |arg|
|
5
|
-
<%= condition %> [[
|
5
|
+
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
6
|
+
<%= arg.render(:validations).indent 2 %>
|
6
7
|
args[<%= arg.name %>]=$1
|
7
8
|
shift
|
8
9
|
% condition = "elif"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bashly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -101,11 +101,16 @@ files:
|
|
101
101
|
- lib/bashly/templates/lib/colors.sh
|
102
102
|
- lib/bashly/templates/lib/config.sh
|
103
103
|
- lib/bashly/templates/lib/sample_function.sh
|
104
|
+
- lib/bashly/templates/lib/validations/validate_dir_exists.sh
|
105
|
+
- lib/bashly/templates/lib/validations/validate_file_exists.sh
|
106
|
+
- lib/bashly/templates/lib/validations/validate_integer.sh
|
107
|
+
- lib/bashly/templates/lib/validations/validate_not_empty.sh
|
104
108
|
- lib/bashly/templates/lib/yaml.sh
|
105
109
|
- lib/bashly/templates/minimal.yml
|
106
110
|
- lib/bashly/templates/strings.yml
|
107
111
|
- lib/bashly/version.rb
|
108
112
|
- lib/bashly/views/argument/usage.erb
|
113
|
+
- lib/bashly/views/argument/validations.erb
|
109
114
|
- lib/bashly/views/command/catch_all_filter.erb
|
110
115
|
- lib/bashly/views/command/command_fallback.erb
|
111
116
|
- lib/bashly/views/command/command_filter.erb
|
@@ -143,6 +148,7 @@ files:
|
|
143
148
|
- lib/bashly/views/environment_variable/usage.erb
|
144
149
|
- lib/bashly/views/flag/case.erb
|
145
150
|
- lib/bashly/views/flag/usage.erb
|
151
|
+
- lib/bashly/views/flag/validations.erb
|
146
152
|
- lib/bashly/views/script/bash3_bouncer.erb
|
147
153
|
- lib/bashly/views/script/header.erb
|
148
154
|
- lib/bashly/views/script/wrapper.erb
|