bashly 0.6.9 → 0.7.3

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bashly/cli.rb +1 -0
  3. data/lib/bashly/commands/add.rb +29 -88
  4. data/lib/bashly/commands/generate.rb +51 -10
  5. data/lib/bashly/commands/init.rb +1 -1
  6. data/lib/bashly/commands/preview.rb +2 -2
  7. data/lib/bashly/commands/validate.rb +19 -0
  8. data/lib/bashly/concerns/asset_helper.rb +4 -0
  9. data/lib/bashly/concerns/command_scopes.rb +68 -0
  10. data/lib/bashly/config_validator.rb +142 -0
  11. data/lib/bashly/extensions/file.rb +13 -0
  12. data/lib/bashly/extensions/string.rb +5 -1
  13. data/lib/bashly/libraries/base.rb +19 -0
  14. data/lib/bashly/libraries/completions.rb +14 -0
  15. data/lib/bashly/libraries/completions_function.rb +38 -0
  16. data/lib/bashly/libraries/completions_script.rb +29 -0
  17. data/lib/bashly/libraries/completions_yaml.rb +27 -0
  18. data/lib/bashly/libraries.yml +39 -0
  19. data/lib/bashly/library.rb +63 -0
  20. data/lib/bashly/refinements/compose_refinements.rb +45 -0
  21. data/lib/bashly/{models → script}/argument.rb +1 -1
  22. data/lib/bashly/{models → script}/base.rb +5 -4
  23. data/lib/bashly/script/catch_all.rb +49 -0
  24. data/lib/bashly/{models → script}/command.rb +10 -112
  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} +2 -2
  28. data/lib/bashly/templates/lib/colors.sh +12 -15
  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 +1 -0
  32. data/lib/bashly/templates/lib/validations/validate_file_exists.sh +1 -0
  33. data/lib/bashly/templates/lib/validations/validate_integer.sh +1 -0
  34. data/lib/bashly/templates/lib/validations/validate_not_empty.sh +1 -0
  35. data/lib/bashly/templates/lib/yaml.sh +12 -15
  36. data/lib/bashly/version.rb +1 -1
  37. data/lib/bashly/views/command/catch_all_filter.erb +2 -2
  38. data/lib/bashly/views/command/command_filter.erb +1 -1
  39. data/lib/bashly/views/command/default_assignments.erb +2 -2
  40. data/lib/bashly/views/command/default_initialize_script.erb +6 -6
  41. data/lib/bashly/views/command/default_root_script.erb +1 -1
  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 -1
  45. data/lib/bashly/views/command/parse_requirements.erb +1 -1
  46. data/lib/bashly/views/command/parse_requirements_case.erb +2 -2
  47. data/lib/bashly/views/command/parse_requirements_while.erb +2 -2
  48. data/lib/bashly/views/command/required_args_filter.erb +1 -6
  49. data/lib/bashly/views/command/required_flags_filter.erb +1 -4
  50. data/lib/bashly/views/command/root_command.erb +1 -1
  51. data/lib/bashly/views/command/run.erb +4 -4
  52. data/lib/bashly/views/command/usage.erb +1 -1
  53. data/lib/bashly/views/command/usage_args.erb +3 -3
  54. data/lib/bashly/views/command/usage_commands.erb +1 -1
  55. data/lib/bashly/views/{script → wrapper}/bash3_bouncer.erb +0 -0
  56. data/lib/bashly/views/{script → wrapper}/header.erb +0 -0
  57. data/lib/bashly/views/{script → wrapper}/wrapper.erb +0 -0
  58. data/lib/bashly.rb +3 -1
  59. metadata +27 -14
@@ -1,3 +1,4 @@
1
+ ## [@bashly-upgrade validations]
1
2
  validate_not_empty() {
2
3
  [[ -z "$1" ]] && echo "must not be empty"
3
4
  }
@@ -1,18 +1,15 @@
1
- # ---
2
- # YAML parser
3
- # This file is a part of Bashly standard library
4
- # Does not support arrays, only hashes
5
- #
6
- # Source: https://stackoverflow.com/a/21189044/413924
7
- #
8
- # Usage:
9
- #
10
- # yaml_load "settings.yml" # print variables
11
- # yaml_load "settings.yml" "config_" # use prefix
12
- # eval $(yaml_load "settings.yml") # create variables in scope
13
- #
14
- # ---
15
-
1
+ ## YAML parser [@bashly-upgrade yaml]
2
+ ## This file is a part of Bashly standard library
3
+ ## Does not support arrays, only hashes
4
+ ##
5
+ ## Source: https://stackoverflow.com/a/21189044/413924
6
+ ##
7
+ ## Usage:
8
+ ##
9
+ ## yaml_load "settings.yml" # print variables
10
+ ## yaml_load "settings.yml" "config_" # use prefix
11
+ ## eval $(yaml_load "settings.yml") # create variables in scope
12
+ ##
16
13
  yaml_load() {
17
14
  local prefix=$2
18
15
  local s='[[:space:]]*' w='[a-zA-Z0-9_]*'
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.6.9"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  # :command.catch_all_filter
2
- % if catch_all_required?
2
+ % if catch_all.required?
3
3
  if [[ ${#other_args[@]} -eq 0 ]]; then
4
- printf "<%= strings[:missing_required_argument] % { arg: catch_all_label, usage: usage_string } %>\n"
4
+ printf "<%= strings[:missing_required_argument] % { arg: catch_all.label, usage: usage_string } %>\n"
5
5
  exit 1
6
6
  fi
7
7
  % end
@@ -1,6 +1,6 @@
1
1
  # :command.command_filter
2
2
  % if commands.any?
3
- action=$1
3
+ action=${1:-}
4
4
 
5
5
  case $action in
6
6
  -* )
@@ -1,7 +1,7 @@
1
1
  # :command.default_assignments
2
2
  % default_args.each do |arg|
3
- [[ -n ${args[<%= arg.name %>]} ]] || args[<%= arg.name %>]="<%= arg.default %>"
3
+ [[ -n ${args[<%= arg.name %>]:-} ]] || args[<%= arg.name %>]="<%= arg.default %>"
4
4
  % end
5
5
  % default_flags.each do |flag|
6
- [[ -n ${args[<%= flag.long %>]} ]] || args[<%= flag.long %>]="<%= flag.default %>"
6
+ [[ -n ${args[<%= flag.long %>]:-} ]] || args[<%= flag.long %>]="<%= flag.default %>"
7
7
  % end
@@ -1,6 +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.
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.
@@ -1,3 +1,3 @@
1
- echo "# this file is located in '<%= Settings.source_dir %>/root_command.sh'"
1
+ echo "# this file is located in '<%= "#{Settings.source_dir}/#{filename}" %>'"
2
2
  echo "# you can edit it freely and regenerate (it will not be overwritten)"
3
3
  inspect_args
@@ -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,7 +2,7 @@
2
2
  initialize() {
3
3
  version="<%= version %>"
4
4
  long_usage=''
5
- set -e
5
+ <%= ENV['BASHLY_STRICT'] ? "set -euo pipefail" : "set -e" %>
6
6
 
7
7
  <%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
8
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 %>
@@ -9,7 +9,7 @@
9
9
  % condition = "elif"
10
10
  % end
11
11
  else
12
- % if catch_all
12
+ % if catch_all.enabled?
13
13
  other_args+=("$1")
14
14
  shift
15
15
  % else
@@ -17,7 +17,7 @@ else
17
17
  exit 1
18
18
  % end
19
19
  fi
20
- % elsif catch_all
20
+ % elsif catch_all.enabled?
21
21
  other_args+=("$1")
22
22
  shift
23
23
  % else
@@ -7,8 +7,8 @@ while [[ $# -gt 0 ]]; do
7
7
 
8
8
  % end
9
9
 
10
- -* )
11
- % if catch_all
10
+ -?* )
11
+ % if catch_all.enabled?
12
12
  other_args+=("$1")
13
13
  shift
14
14
  ;;
@@ -1,12 +1,7 @@
1
1
  # :command.required_args_filter
2
2
  % required_args.each do |arg|
3
- if [[ -n ${1+x} && $1 != -* ]]; then
4
- <%= arg.render(:validations).indent 2 %>
5
- args[<%= arg.name %>]=$1
6
- shift
7
- else
3
+ if [[ -z ${args[<%= arg.name %>]+x} ]]; then
8
4
  printf "<%= strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } %>\n"
9
5
  exit 1
10
6
  fi
11
-
12
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,4 +1,4 @@
1
1
  # :command.root_command
2
2
  root_command() {
3
- <%= load_user_file("root_command.sh").indent 2 %>
3
+ <%= load_user_file(filename).indent 2 %>
4
4
  }
@@ -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
@@ -37,7 +37,7 @@
37
37
  printf "<%= strings[:options] %>\n"
38
38
  <%= render(:usage_fixed_flags).indent 4 %>
39
39
  <%= render(:usage_flags).indent 4 if flags.any? %>
40
- <%= render(:usage_args).indent 4 if args.any? or catch_all_help %>
40
+ <%= render(:usage_args).indent 4 if args.any? or catch_all.help %>
41
41
  <%= render(:usage_environment_variables).indent 4 if environment_variables.any? %>
42
42
  <%= render(:usage_examples).indent 4 if examples %>
43
43
  <%= render(:footer).indent 4 if footer %>
@@ -6,9 +6,9 @@ printf "<%= strings[:arguments] %>\n"
6
6
  <%= arg.render(:usage) %>
7
7
  % end
8
8
  % end
9
- % if catch_all_help
9
+ % if catch_all.help
10
10
 
11
- echo " <%= catch_all_label %>"
12
- printf "<%= catch_all_help.wrap(76).indent(4).sanitize_for_print %>\n"
11
+ echo " <%= catch_all.label %>"
12
+ printf "<%= catch_all.help.wrap(76).indent(4).sanitize_for_print %>\n"
13
13
  echo
14
14
  % end
@@ -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
File without changes
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.9
4
+ version: 0.7.3
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-26 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mister_bin
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -82,20 +82,33 @@ 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
87
+ - lib/bashly/concerns/command_scopes.rb
86
88
  - lib/bashly/concerns/completions.rb
87
89
  - lib/bashly/concerns/renderable.rb
88
90
  - lib/bashly/config.rb
91
+ - lib/bashly/config_validator.rb
89
92
  - lib/bashly/exceptions.rb
90
93
  - lib/bashly/extensions/array.rb
94
+ - lib/bashly/extensions/file.rb
91
95
  - lib/bashly/extensions/string.rb
96
+ - lib/bashly/libraries.yml
97
+ - lib/bashly/libraries/base.rb
98
+ - lib/bashly/libraries/completions.rb
99
+ - lib/bashly/libraries/completions_function.rb
100
+ - lib/bashly/libraries/completions_script.rb
101
+ - lib/bashly/libraries/completions_yaml.rb
102
+ - lib/bashly/library.rb
92
103
  - 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
104
+ - lib/bashly/refinements/compose_refinements.rb
105
+ - lib/bashly/script/argument.rb
106
+ - lib/bashly/script/base.rb
107
+ - lib/bashly/script/catch_all.rb
108
+ - lib/bashly/script/command.rb
109
+ - lib/bashly/script/environment_variable.rb
110
+ - lib/bashly/script/flag.rb
111
+ - lib/bashly/script/wrapper.rb
99
112
  - lib/bashly/settings.rb
100
113
  - lib/bashly/templates/bashly.yml
101
114
  - lib/bashly/templates/lib/colors.sh
@@ -149,9 +162,9 @@ files:
149
162
  - lib/bashly/views/flag/case.erb
150
163
  - lib/bashly/views/flag/usage.erb
151
164
  - lib/bashly/views/flag/validations.erb
152
- - lib/bashly/views/script/bash3_bouncer.erb
153
- - lib/bashly/views/script/header.erb
154
- - lib/bashly/views/script/wrapper.erb
165
+ - lib/bashly/views/wrapper/bash3_bouncer.erb
166
+ - lib/bashly/views/wrapper/header.erb
167
+ - lib/bashly/views/wrapper/wrapper.erb
155
168
  homepage: https://github.com/dannyben/bashly
156
169
  licenses:
157
170
  - MIT
@@ -175,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
188
  - !ruby/object:Gem::Version
176
189
  version: '0'
177
190
  requirements: []
178
- rubygems_version: 3.2.25
191
+ rubygems_version: 3.3.6
179
192
  signing_key:
180
193
  specification_version: 4
181
194
  summary: Bash Command Line Tool Generator