bashly 0.6.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/lib/bashly/cli.rb +1 -0
  4. data/lib/bashly/commands/add.rb +35 -82
  5. data/lib/bashly/commands/generate.rb +55 -9
  6. data/lib/bashly/commands/init.rb +1 -1
  7. data/lib/bashly/commands/preview.rb +2 -2
  8. data/lib/bashly/commands/validate.rb +19 -0
  9. data/lib/bashly/concerns/asset_helper.rb +4 -0
  10. data/lib/bashly/concerns/completions.rb +5 -1
  11. data/lib/bashly/config_validator.rb +135 -0
  12. data/lib/bashly/extensions/file.rb +13 -0
  13. data/lib/bashly/extensions/string.rb +5 -1
  14. data/lib/bashly/libraries/base.rb +19 -0
  15. data/lib/bashly/libraries/completions.rb +14 -0
  16. data/lib/bashly/libraries/completions_function.rb +38 -0
  17. data/lib/bashly/libraries/completions_script.rb +29 -0
  18. data/lib/bashly/libraries/completions_yaml.rb +27 -0
  19. data/lib/bashly/libraries.yml +39 -0
  20. data/lib/bashly/library.rb +63 -0
  21. data/lib/bashly/refinements/compose_refinements.rb +45 -0
  22. data/lib/bashly/{models → script}/argument.rb +1 -1
  23. data/lib/bashly/{models → script}/base.rb +4 -2
  24. data/lib/bashly/{models → script}/command.rb +11 -22
  25. data/lib/bashly/{models → script}/environment_variable.rb +1 -1
  26. data/lib/bashly/{models → script}/flag.rb +1 -1
  27. data/lib/bashly/{models/script.rb → script/wrapper.rb} +21 -3
  28. data/lib/bashly/templates/lib/colors.sh +41 -31
  29. data/lib/bashly/templates/lib/config.sh +34 -35
  30. data/lib/bashly/templates/lib/sample_function.sh +10 -10
  31. data/lib/bashly/templates/lib/validations/validate_dir_exists.sh +4 -0
  32. data/lib/bashly/templates/lib/validations/validate_file_exists.sh +4 -0
  33. data/lib/bashly/templates/lib/validations/validate_integer.sh +4 -0
  34. data/lib/bashly/templates/lib/validations/validate_not_empty.sh +4 -0
  35. data/lib/bashly/templates/lib/yaml.sh +12 -15
  36. data/lib/bashly/templates/strings.yml +1 -0
  37. data/lib/bashly/version.rb +1 -1
  38. data/lib/bashly/views/argument/validations.erb +8 -0
  39. data/lib/bashly/views/command/command_filter.erb +1 -1
  40. data/lib/bashly/views/command/default_assignments.erb +2 -2
  41. data/lib/bashly/views/command/default_initialize_script.erb +6 -6
  42. data/lib/bashly/views/command/environment_variables_filter.erb +1 -1
  43. data/lib/bashly/views/command/fixed_flags_filter.erb +1 -1
  44. data/lib/bashly/views/command/initialize.erb +1 -6
  45. data/lib/bashly/views/command/parse_requirements.erb +1 -1
  46. data/lib/bashly/views/command/parse_requirements_case.erb +2 -1
  47. data/lib/bashly/views/command/required_args_filter.erb +1 -5
  48. data/lib/bashly/views/command/required_flags_filter.erb +1 -4
  49. data/lib/bashly/views/command/run.erb +4 -4
  50. data/lib/bashly/views/command/usage_commands.erb +1 -1
  51. data/lib/bashly/views/flag/case.erb +2 -1
  52. data/lib/bashly/views/flag/validations.erb +8 -0
  53. data/lib/bashly/views/wrapper/bash3_bouncer.erb +5 -0
  54. data/lib/bashly/views/{script → wrapper}/header.erb +1 -0
  55. data/lib/bashly/views/{script → wrapper}/wrapper.erb +0 -0
  56. data/lib/bashly.rb +3 -1
  57. metadata +28 -10
@@ -6,7 +6,7 @@ export <%= env_var.name.upcase %>="${<%= env_var.name.upcase %>:-<%= env_var.def
6
6
  % end
7
7
  % if required_environment_variables.any?
8
8
  % required_environment_variables.each do |env_var|
9
- if [[ -z "$<%= env_var.name.upcase %>" ]]; then
9
+ if [[ -z "${<%= env_var.name.upcase %>:-}" ]]; then
10
10
  printf "<%= strings[:missing_required_environment_variable] % { var: env_var.name.upcase } %>\n"
11
11
  exit 1
12
12
  fi
@@ -1,5 +1,5 @@
1
1
  # :command.fixed_flag_filter
2
- case "$1" in
2
+ case "${1:-}" in
3
3
  % if short_flag_exist? "-v"
4
4
  --version )
5
5
  % else
@@ -2,12 +2,7 @@
2
2
  initialize() {
3
3
  version="<%= version %>"
4
4
  long_usage=''
5
- set -e
6
-
7
- if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
8
- printf "<%= strings[:unsupported_bash_version] -%>\n"
9
- exit 1
10
- fi
5
+ <%= ENV['BASHLY_STRICT'] ? "set -euo pipefail" : "set -e" %>
11
6
 
12
7
  <%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
13
8
  }
@@ -8,9 +8,9 @@ parse_requirements() {
8
8
  <%= render(:environment_variables_filter).indent 2 %>
9
9
  <%= render(:dependencies_filter).indent 2 %>
10
10
  <%= render(:command_filter).indent 2 %>
11
+ <%= render(:parse_requirements_while).indent 2 %>
11
12
  <%= render(:required_args_filter).indent 2 %>
12
13
  <%= render(:required_flags_filter).indent 2 %>
13
- <%= render(:parse_requirements_while).indent 2 %>
14
14
  <%= render(:catch_all_filter).indent 2 %>
15
15
  <%= render(:default_assignments).indent 2 %>
16
16
  <%= render(:whitelist_filter).indent 2 %>
@@ -2,7 +2,8 @@
2
2
  % if args.any?
3
3
  % condition = "if"
4
4
  % args.each do |arg|
5
- <%= condition %> [[ ! ${args[<%= arg.name %>]} ]]; then
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"
@@ -1,11 +1,7 @@
1
1
  # :command.required_args_filter
2
2
  % required_args.each do |arg|
3
- if [[ $1 && $1 != -* ]]; then
4
- args[<%= arg.name %>]=$1
5
- shift
6
- else
3
+ if [[ -z ${args[<%= arg.name %>]+x} ]]; then
7
4
  printf "<%= strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } %>\n"
8
5
  exit 1
9
6
  fi
10
-
11
7
  % end
@@ -1,9 +1,6 @@
1
1
  # :command.required_flags_filter
2
- % if required_flags.any?
3
- argstring="$*"
4
- % end
5
2
  % required_flags.each do |flag|
6
- if [[ <%= flag.aliases.map { |a| %Q["$argstring" != *#{a}*] }.join " && " %> ]]; then
3
+ if [[ -z ${args[<%= flag.long %>]+x} ]]; then
7
4
  printf "<%= strings[:missing_required_flag] % { usage: flag.usage_string } %>\n"
8
5
  exit 1
9
6
  fi
@@ -1,15 +1,15 @@
1
1
  # :command.run
2
2
  run() {
3
- declare -A args
4
- declare -a other_args
5
- declare -a input
3
+ declare -A args=()
4
+ declare -a other_args=()
5
+ declare -a input=()
6
6
  normalize_input "$@"
7
7
  parse_requirements "${input[@]}"
8
8
 
9
9
  <%- condition = "if" -%>
10
10
  <%- deep_commands.each do |command| -%>
11
11
  <%= condition %> [[ $action == "<%= command.action_name %>" ]]; then
12
- if [[ ${args[--help]} ]]; then
12
+ if [[ ${args[--help]:-} ]]; then
13
13
  long_usage=yes
14
14
  <%= command.function_name %>_usage
15
15
  else
@@ -3,7 +3,7 @@
3
3
  printf "<%= strings[:commands] %>\n"
4
4
  % end
5
5
  % maxlen = command_names.map(&:size).max
6
- % commands.each do |command|
6
+ % commands.reject(&:private).each do |command|
7
7
  % summary = command.summary
8
8
  % summary = strings[:default_command_summary] % { summary: summary } if command.default
9
9
  % if command.group
@@ -1,7 +1,8 @@
1
1
  # :flag.case
2
2
  <%= aliases.join " | " %> )
3
3
  % if arg
4
- if [[ $2 ]]; then
4
+ if [[ -n ${2+x} ]]; then
5
+ <%= render(:validations).indent 4 %>
5
6
  args[<%= name %>]="$2"
6
7
  shift
7
8
  shift
@@ -0,0 +1,8 @@
1
+ # :flag.validations
2
+ % if validate
3
+ if [[ -n $(validate_<%= validate %> "$2") ]]; then
4
+ printf "<%= strings[:validation_error] %>\n" "<%= usage_string %>" "$(validate_<%= validate %> "$2")"
5
+ exit 1
6
+ fi
7
+
8
+ % end
@@ -0,0 +1,5 @@
1
+ # :script.bash3_bouncer
2
+ if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
3
+ printf "<%= strings[:unsupported_bash_version] -%>\n"
4
+ exit 1
5
+ fi
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env bash
2
2
  # This script was generated by bashly (https://github.com/DannyBen/bashly)
3
3
  # Modifying it manually is not recommended
4
+
File without changes
data/lib/bashly.rb CHANGED
@@ -9,6 +9,8 @@ requires 'bashly/concerns'
9
9
 
10
10
  requires 'bashly/settings'
11
11
  requires 'bashly/exceptions'
12
- requires 'bashly/models/base'
12
+ requires 'bashly/refinements'
13
+ requires 'bashly/script/base'
13
14
  requires 'bashly/commands/base'
15
+ requires 'bashly/libraries/base'
14
16
  requires 'bashly'
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.7
4
+ version: 0.7.1
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-09-27 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -82,30 +82,46 @@ files:
82
82
  - lib/bashly/commands/generate.rb
83
83
  - lib/bashly/commands/init.rb
84
84
  - lib/bashly/commands/preview.rb
85
+ - lib/bashly/commands/validate.rb
85
86
  - lib/bashly/concerns/asset_helper.rb
86
87
  - lib/bashly/concerns/completions.rb
87
88
  - lib/bashly/concerns/renderable.rb
88
89
  - lib/bashly/config.rb
90
+ - lib/bashly/config_validator.rb
89
91
  - lib/bashly/exceptions.rb
90
92
  - lib/bashly/extensions/array.rb
93
+ - lib/bashly/extensions/file.rb
91
94
  - lib/bashly/extensions/string.rb
95
+ - lib/bashly/libraries.yml
96
+ - lib/bashly/libraries/base.rb
97
+ - lib/bashly/libraries/completions.rb
98
+ - lib/bashly/libraries/completions_function.rb
99
+ - lib/bashly/libraries/completions_script.rb
100
+ - lib/bashly/libraries/completions_yaml.rb
101
+ - lib/bashly/library.rb
92
102
  - lib/bashly/message_strings.rb
93
- - lib/bashly/models/argument.rb
94
- - lib/bashly/models/base.rb
95
- - lib/bashly/models/command.rb
96
- - lib/bashly/models/environment_variable.rb
97
- - lib/bashly/models/flag.rb
98
- - lib/bashly/models/script.rb
103
+ - lib/bashly/refinements/compose_refinements.rb
104
+ - lib/bashly/script/argument.rb
105
+ - lib/bashly/script/base.rb
106
+ - lib/bashly/script/command.rb
107
+ - lib/bashly/script/environment_variable.rb
108
+ - lib/bashly/script/flag.rb
109
+ - lib/bashly/script/wrapper.rb
99
110
  - lib/bashly/settings.rb
100
111
  - lib/bashly/templates/bashly.yml
101
112
  - lib/bashly/templates/lib/colors.sh
102
113
  - lib/bashly/templates/lib/config.sh
103
114
  - lib/bashly/templates/lib/sample_function.sh
115
+ - lib/bashly/templates/lib/validations/validate_dir_exists.sh
116
+ - lib/bashly/templates/lib/validations/validate_file_exists.sh
117
+ - lib/bashly/templates/lib/validations/validate_integer.sh
118
+ - lib/bashly/templates/lib/validations/validate_not_empty.sh
104
119
  - lib/bashly/templates/lib/yaml.sh
105
120
  - lib/bashly/templates/minimal.yml
106
121
  - lib/bashly/templates/strings.yml
107
122
  - lib/bashly/version.rb
108
123
  - lib/bashly/views/argument/usage.erb
124
+ - lib/bashly/views/argument/validations.erb
109
125
  - lib/bashly/views/command/catch_all_filter.erb
110
126
  - lib/bashly/views/command/command_fallback.erb
111
127
  - lib/bashly/views/command/command_filter.erb
@@ -143,8 +159,10 @@ files:
143
159
  - lib/bashly/views/environment_variable/usage.erb
144
160
  - lib/bashly/views/flag/case.erb
145
161
  - lib/bashly/views/flag/usage.erb
146
- - lib/bashly/views/script/header.erb
147
- - lib/bashly/views/script/wrapper.erb
162
+ - lib/bashly/views/flag/validations.erb
163
+ - lib/bashly/views/wrapper/bash3_bouncer.erb
164
+ - lib/bashly/views/wrapper/header.erb
165
+ - lib/bashly/views/wrapper/wrapper.erb
148
166
  homepage: https://github.com/dannyben/bashly
149
167
  licenses:
150
168
  - MIT