bashly 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/lib/bashly/concerns/renderable.rb +3 -0
- data/lib/bashly/models/command.rb +12 -2
- data/lib/bashly/models/flag.rb +4 -0
- data/lib/bashly/polyfills/hash.rb +3 -1
- data/lib/bashly/templates/lib/config.sh +15 -4
- data/lib/bashly/templates/lib/sample_function.sh +1 -1
- data/lib/bashly/templates/strings.yml +2 -1
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/argument/usage.erb +3 -0
- data/lib/bashly/views/command/default_assignments.erb +7 -0
- data/lib/bashly/views/command/fixed_flags_filter.erb +1 -1
- data/lib/bashly/views/command/parse_requirements.erb +1 -0
- data/lib/bashly/views/flag/case.erb +3 -3
- data/lib/bashly/views/flag/usage.erb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ee3d9cf49b4497ffbb7e374894cc0cfe18e1a1493a58c638cf4fd8896f30e2
|
4
|
+
data.tar.gz: 18dd37e6cfc3efd1f3c3d103f943e5ba8db4b414b2b26bed1bb096728c40cd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2564fbacc1cd7584e6a0a4da943a25fa70bb51e01a935e18e1c15cb98f3a95e75147f404f858f294df26e18499233e1f82d99f3b344a8464e8ecfccd90c5a0e2
|
7
|
+
data.tar.gz: d638eff5ef4a4d407b558ba153e199ede105fe34b23ee00b7c8961c843cd8e5ef23e21de1396c92b6f3742f9ec7585f02ac182ccd19329b0008f5c2f5b702cc7
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Bashly - Bash CLI Framework and Generator
|
|
7
7
|
Create beautiful bash scripts from simple YAML configuration
|
8
8
|
|
9
9
|
[![Gem Version](https://badge.fury.io/rb/bashly.svg)](https://badge.fury.io/rb/bashly)
|
10
|
-
[![Build Status](https://
|
10
|
+
[![Build Status](https://github.com/DannyBen/bashly/workflows/Test/badge.svg)](https://github.com/DannyBen/bashly/actions?query=workflow%3ATest)
|
11
11
|
[![Maintainability](https://api.codeclimate.com/v1/badges/8cf89047e50ca601e431/maintainability)](https://codeclimate.com/github/DannyBen/bashly/maintainability)
|
12
12
|
|
13
13
|
---
|
@@ -25,6 +25,18 @@ Installation
|
|
25
25
|
$ gem install bashly
|
26
26
|
```
|
27
27
|
|
28
|
+
or with Docker:
|
29
|
+
|
30
|
+
```shell
|
31
|
+
$ alias bashly='docker run --rm -it --volume "$PWD:/app" dannyben/bashly'
|
32
|
+
```
|
33
|
+
|
34
|
+
Prerequisites
|
35
|
+
--------------------------------------------------
|
36
|
+
|
37
|
+
The bash scripts generated by bashly require bash 4 or higher due to heavy
|
38
|
+
use of associative arrays.
|
39
|
+
|
28
40
|
|
29
41
|
What is Bashly
|
30
42
|
--------------------------------------------------
|
@@ -54,6 +66,7 @@ Bahsly is responsible for:
|
|
54
66
|
- **Color output**.
|
55
67
|
- **Config file management** (INI format).
|
56
68
|
- **YAML parsing**.
|
69
|
+
- and more.
|
57
70
|
|
58
71
|
Usage
|
59
72
|
--------------------------------------------------
|
@@ -159,6 +172,7 @@ bash function.
|
|
159
172
|
`name` | The name of the argument.
|
160
173
|
`help` | The message to display when using `--help`. Can have multiple lines.
|
161
174
|
`required` | Specify if this argument is required. Note that once you define an optional argument (without required: true) then you cannot define required arguments after it.
|
175
|
+
`default` | The value to use in case it is not provided by the user. Implies that this argument is optional.
|
162
176
|
|
163
177
|
### Flag options
|
164
178
|
|
@@ -173,6 +187,7 @@ short form).
|
|
173
187
|
`help` | The text to display when using `--help`. Can have multiple lines.
|
174
188
|
`arg` | If the flag requires an argument, specify its name here.
|
175
189
|
`required` | Specify if this flag is required.
|
190
|
+
`default` | The value to use in case it is not provided by the user. Implies that this flag is optional, and only makes sense when the flag has an argument.
|
176
191
|
|
177
192
|
#### Special handling for -v and -h
|
178
193
|
|
@@ -199,6 +214,8 @@ Real World Examples
|
|
199
214
|
--------------------------------------------------
|
200
215
|
|
201
216
|
- [Rush][rush] - a Personal Package Manager
|
217
|
+
- [Alf][alf] - a generator for bash aliases and sub-aliases
|
218
|
+
- [git-changelog][git-changelog] - a change log generator
|
202
219
|
|
203
220
|
|
204
221
|
Contributing / Support
|
@@ -209,3 +226,7 @@ to contribute, feel free to [open an issue][issues].
|
|
209
226
|
|
210
227
|
[issues]: https://github.com/DannyBen/bashly/issues
|
211
228
|
[rush]: https://github.com/DannyBen/rush-cli
|
229
|
+
[alf]: https://github.com/DannyBen/alf
|
230
|
+
[git-changelog]: https://github.com/DannyBen/git-changelog
|
231
|
+
|
232
|
+
|
@@ -4,6 +4,9 @@ module Bashly
|
|
4
4
|
module Renderable
|
5
5
|
def render(view)
|
6
6
|
template = File.read view_path(view)
|
7
|
+
# TODO: This new format is only supported in Ruby >= 2.6
|
8
|
+
# So for now, we keep the old deprecated syntax
|
9
|
+
# ERB.new(template, trim_mode: '%-').result(binding)
|
7
10
|
ERB.new(template, nil, '%-').result(binding)
|
8
11
|
end
|
9
12
|
|
@@ -38,7 +38,7 @@ module Bashly
|
|
38
38
|
return [] unless options["commands"]
|
39
39
|
options["commands"].map do |options|
|
40
40
|
options['parents'] = parents + [name]
|
41
|
-
|
41
|
+
Command.new options
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -55,12 +55,22 @@ module Bashly
|
|
55
55
|
result
|
56
56
|
end
|
57
57
|
|
58
|
+
# Returns an array of all the default Args
|
59
|
+
def default_args
|
60
|
+
args.select &:default
|
61
|
+
end
|
62
|
+
|
58
63
|
# If any of this command's subcommands has the default option set to
|
59
64
|
# true, this default command will be returned, nil otherwise.
|
60
65
|
def default_command
|
61
66
|
commands.find { |c| c.default }
|
62
67
|
end
|
63
68
|
|
69
|
+
# Returns an array of all the default Flags
|
70
|
+
def default_flags
|
71
|
+
flags.select &:default
|
72
|
+
end
|
73
|
+
|
64
74
|
# Returns an array of EnvironmentVariables
|
65
75
|
def environment_variables
|
66
76
|
return [] unless options["environment_variables"]
|
@@ -148,7 +158,7 @@ module Bashly
|
|
148
158
|
args.each do |arg|
|
149
159
|
result << arg.usage_string
|
150
160
|
end
|
151
|
-
result << "[options]"
|
161
|
+
result << "[options]" unless flags.empty?
|
152
162
|
result.join " "
|
153
163
|
end
|
154
164
|
|
data/lib/bashly/models/flag.rb
CHANGED
@@ -21,7 +21,7 @@ config_init() {
|
|
21
21
|
# Usage: result=$(config_get hello)
|
22
22
|
config_get() {
|
23
23
|
key=$1
|
24
|
-
regex="^$key
|
24
|
+
regex="^$key *= *(.+)$"
|
25
25
|
|
26
26
|
config_init
|
27
27
|
|
@@ -44,7 +44,7 @@ config_set() {
|
|
44
44
|
|
45
45
|
config_init
|
46
46
|
|
47
|
-
regex="^($key)
|
47
|
+
regex="^($key) *= *.+$"
|
48
48
|
output=""
|
49
49
|
found_key=""
|
50
50
|
|
@@ -71,7 +71,7 @@ config_set() {
|
|
71
71
|
config_del() {
|
72
72
|
key=$1
|
73
73
|
|
74
|
-
regex="^($key)
|
74
|
+
regex="^($key) *="
|
75
75
|
output=""
|
76
76
|
|
77
77
|
config_init
|
@@ -100,7 +100,7 @@ config_show() {
|
|
100
100
|
# done
|
101
101
|
#
|
102
102
|
config_keys() {
|
103
|
-
regex="^(
|
103
|
+
regex="^([a-zA-Z0-9_\-\/\.]+) *="
|
104
104
|
|
105
105
|
config_init
|
106
106
|
|
@@ -113,3 +113,14 @@ config_keys() {
|
|
113
113
|
done < "$CONFIG_FILE"
|
114
114
|
echo "${keys[@]}"
|
115
115
|
}
|
116
|
+
|
117
|
+
# Returns true if the specified key exists in the config file
|
118
|
+
# Usage:
|
119
|
+
#
|
120
|
+
# if config_has_key "key" ; then
|
121
|
+
# echo "key exists"
|
122
|
+
# fi
|
123
|
+
#
|
124
|
+
config_has_key() {
|
125
|
+
[[ $(config_get "$1") ]]
|
126
|
+
}
|
@@ -14,13 +14,14 @@ group: "%{group} Commands:"
|
|
14
14
|
command_shortcut: "Shortcut: %{short}"
|
15
15
|
default_command_summary: "%{summary} (default)"
|
16
16
|
required: "(required)"
|
17
|
+
default: "Default: %{value}"
|
17
18
|
|
18
19
|
# Fixed flags help text
|
19
20
|
help_flag_text: Show this help
|
20
21
|
version_flag_text: Show version number
|
21
22
|
|
22
23
|
# Error messages
|
23
|
-
flag_requires_an_argument: "%{
|
24
|
+
flag_requires_an_argument: "%{name} requires an argument: %{usage}"
|
24
25
|
invalid_argument: "invalid argument: %s"
|
25
26
|
invalid_flag: "invalid option: %s"
|
26
27
|
missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
data/lib/bashly/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
# :command.default_assignments
|
2
|
+
<%- default_args.each do |arg| -%>
|
3
|
+
[[ -n ${args[<%= arg.name %>]} ]] || args[<%= arg.name %>]="<%= arg.default %>"
|
4
|
+
<%- end -%>
|
5
|
+
<%- default_flags.each do |flag| -%>
|
6
|
+
[[ -n ${args[<%= flag.long %>]} ]] || args[<%= flag.long %>]="<%= flag.default %>"
|
7
|
+
<%- end -%>
|
@@ -11,6 +11,7 @@ parse_requirements() {
|
|
11
11
|
<%= render(:required_args_filter).indent 2 %>
|
12
12
|
<%= render(:required_flags_filter).indent 2 %>
|
13
13
|
<%= render(:parse_requirements_while).indent 2 %>
|
14
|
+
<%= render(:default_assignments).indent 2 %>
|
14
15
|
}
|
15
16
|
|
16
17
|
<%- commands.each do |command| %>
|
@@ -2,15 +2,15 @@
|
|
2
2
|
<%= aliases.join " | " %> )
|
3
3
|
<%- if arg -%>
|
4
4
|
if [[ $2 && $2 != -* ]]; then
|
5
|
-
args[<%=
|
5
|
+
args[<%= name %>]="$2"
|
6
6
|
shift
|
7
7
|
shift
|
8
8
|
else
|
9
|
-
printf "%s\n" "<%= strings[:flag_requires_an_argument] % {
|
9
|
+
printf "%s\n" "<%= strings[:flag_requires_an_argument] % { name: name, usage: usage_string } %>"
|
10
10
|
exit 1
|
11
11
|
fi
|
12
12
|
<%- else -%>
|
13
|
-
args[<%=
|
13
|
+
args[<%= name %>]=1
|
14
14
|
shift
|
15
15
|
<%- end -%>
|
16
16
|
;;
|
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.
|
4
|
+
version: 0.4.0
|
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:
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/bashly/views/argument/usage.erb
|
94
94
|
- lib/bashly/views/command/command_filter.erb
|
95
95
|
- lib/bashly/views/command/command_functions.erb
|
96
|
+
- lib/bashly/views/command/default_assignments.erb
|
96
97
|
- lib/bashly/views/command/default_initialize_script.erb
|
97
98
|
- lib/bashly/views/command/default_root_script.erb
|
98
99
|
- lib/bashly/views/command/default_script.erb
|
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.1.4
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: Bash Command Line Tool Generator
|