bashly 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +195 -1
- data/lib/bashly.rb +1 -0
- data/lib/bashly/commands/generate.rb +2 -0
- data/lib/bashly/polyfills/hash.rb +10 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/inspect_args.erb +1 -1
- data/lib/bashly/views/command/master_script.erb +2 -0
- data/lib/bashly/views/command/parse_args_case.erb +2 -2
- data/lib/bashly/views/command/parse_args_while.erb +1 -1
- data/lib/bashly/views/command/required_args_filter.erb +2 -2
- data/lib/bashly/views/command/required_flags_filter.erb +4 -1
- data/lib/bashly/views/command/version_command.erb +1 -1
- data/lib/bashly/views/flag/case.erb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4dbc588718b280b13a81c8adbd2f4f86da7ec536baf3666d58592bfb2854ac5
|
4
|
+
data.tar.gz: 867936a132914810eb18cfb6b3ce10d36844c1e20ed348279374d4c2f2311bc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1d3adacfcc29c6d74a0bbaa9ff339ce6150d1035588d2641f9094c486a572111c205e1d233bd9023e44e56c1f2c8e223488d34b5c3427f67b1291c7478598f5
|
7
|
+
data.tar.gz: 70884518d2343dd3915f03ecd0cf46809324c1a026fc28f9245ae57bd7e2587a5fb4a9a6e7a4cd5137b9d8110a28bb415658de48c7eb63d58e3b27bd4cb64403
|
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
Bashly -
|
1
|
+
Bashly - Bash CLI Generator
|
2
2
|
==================================================
|
3
3
|
|
4
4
|
Create beautiful bash scripts from simple YAML configuration.
|
5
5
|
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/bashly.svg)](https://badge.fury.io/rb/bashly)
|
7
|
+
[![Build Status](https://travis-ci.com/DannyBen/bashly.svg?branch=master)](https://travis-ci.com/DannyBen/bashly)
|
8
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/8cf89047e50ca601e431/maintainability)](https://codeclimate.com/github/DannyBen/bashly/maintainability)
|
9
|
+
|
10
|
+
---
|
11
|
+
|
6
12
|
![demo](demo/cast.svg)
|
7
13
|
|
8
14
|
---
|
@@ -41,8 +47,196 @@ get their own file. Once you edit, run `bashly generate` again to merge the
|
|
41
47
|
content from your functions back into the script.
|
42
48
|
|
43
49
|
|
50
|
+
Examples
|
51
|
+
--------------------------------------------------
|
52
|
+
|
53
|
+
The `bashly.yml` file can be set up to generate two types of scripts:
|
54
|
+
|
55
|
+
1. Script with subcommands (for example, like `docker` or `git`).
|
56
|
+
2. Script without subcommands (for example, like `ls`)
|
57
|
+
|
58
|
+
This is detected automatically by the contents of the configuration: If it
|
59
|
+
contains a `commands` definition, it will generate a script with subcommands.
|
60
|
+
|
61
|
+
|
62
|
+
### Sample configuraiton for a script without subcommands
|
63
|
+
|
64
|
+
You can get this script by running `bashly generate --minimal`.
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
name: download
|
68
|
+
help: Sample minimal application without subcommands
|
69
|
+
version: 0.1.0
|
70
|
+
|
71
|
+
args:
|
72
|
+
- name: source
|
73
|
+
required: true
|
74
|
+
help: URL to download from
|
75
|
+
- name: target
|
76
|
+
help: "Target filename (default: same as source)"
|
77
|
+
|
78
|
+
flags:
|
79
|
+
- long: --force
|
80
|
+
short: -f
|
81
|
+
help: Overwrite existing files
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
### Sample configuraiton for a script with subcommands
|
86
|
+
|
87
|
+
You can get this script by running `bashly generate`.
|
88
|
+
|
89
|
+
```yaml
|
90
|
+
name: cli
|
91
|
+
help: Sample application
|
92
|
+
version: 0.1.0
|
93
|
+
|
94
|
+
commands:
|
95
|
+
- name: download
|
96
|
+
short: d
|
97
|
+
help: Download a file
|
98
|
+
|
99
|
+
args:
|
100
|
+
- name: source
|
101
|
+
required: true
|
102
|
+
help: URL to download from
|
103
|
+
- name: target
|
104
|
+
help: "Target filename (default: same as source)"
|
105
|
+
|
106
|
+
flags:
|
107
|
+
- long: --force
|
108
|
+
short: -f
|
109
|
+
help: Overwrite existing files
|
110
|
+
|
111
|
+
- name: upload
|
112
|
+
short: u
|
113
|
+
help: Upload a file
|
114
|
+
args:
|
115
|
+
- name: source
|
116
|
+
required: true
|
117
|
+
help: File to upload
|
118
|
+
|
119
|
+
flags:
|
120
|
+
- long: --user
|
121
|
+
short: -u
|
122
|
+
arg: user
|
123
|
+
help: Username to use for logging in
|
124
|
+
required: true
|
125
|
+
- long: --password
|
126
|
+
short: -p
|
127
|
+
arg: password
|
128
|
+
help: Password to use for logging in
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
Configuration Reference
|
133
|
+
--------------------------------------------------
|
134
|
+
|
135
|
+
### Command options
|
136
|
+
|
137
|
+
With the exception of `version` and `commands` (shich define subcommands),
|
138
|
+
everything else in this section is suitable both for the main script, and for
|
139
|
+
any subcommand you define using `commands`.
|
140
|
+
|
141
|
+
```yaml
|
142
|
+
# The name of the script or subcommand
|
143
|
+
name: myscript
|
144
|
+
|
145
|
+
# The header text to display when using --help
|
146
|
+
# This can have multiple lines. In this case, the first line will be used as
|
147
|
+
# summary wherever appropriate.
|
148
|
+
help: a sample script generated with bashly
|
149
|
+
|
150
|
+
# The string to display when using --version
|
151
|
+
version: 0.1.0
|
152
|
+
|
153
|
+
# Specify the array of subcommands to generate.
|
154
|
+
# Each subcommand will have its own args and flags.
|
155
|
+
# If this is provided, then you cannot provide flags or args for the main
|
156
|
+
# script.
|
157
|
+
commands:
|
158
|
+
- ...
|
159
|
+
|
160
|
+
# Specify the array of positional arguments this script needs.
|
161
|
+
# If this is provided, then you cannot provide commands for the main script.
|
162
|
+
args:
|
163
|
+
- ...
|
164
|
+
|
165
|
+
# Specify the array of option flags this script needs.
|
166
|
+
# If this is provided, then you cannot provide commands for the main script.
|
167
|
+
flags:
|
168
|
+
- ...
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
### Argument options
|
173
|
+
|
174
|
+
The below configuration generates this argument:
|
175
|
+
|
176
|
+
```
|
177
|
+
Usage:
|
178
|
+
myscript USER
|
179
|
+
|
180
|
+
Arguments:
|
181
|
+
USER
|
182
|
+
Username to use for logging in
|
183
|
+
```
|
184
|
+
|
185
|
+
The argument's value will be available to you as `${args[user]}` in your
|
186
|
+
bash function.
|
187
|
+
|
188
|
+
```yaml
|
189
|
+
# The name of the argument.
|
190
|
+
name: user
|
191
|
+
|
192
|
+
# The message to display when using --help.
|
193
|
+
# This can have multiple lines, but it is recommended to keep lines shorter
|
194
|
+
# than ~70 characters, to avoid text wrapping in narrower terminals.
|
195
|
+
help: Username to use for logging in
|
196
|
+
|
197
|
+
# Specify if this argument is required.
|
198
|
+
# Note that once you define an optional argument (without required: true)
|
199
|
+
# then you cannot define required arguments after it.
|
200
|
+
required: true
|
201
|
+
```
|
202
|
+
|
203
|
+
### Flag options
|
204
|
+
|
205
|
+
The below configuration generates this flag:
|
206
|
+
|
207
|
+
```
|
208
|
+
-o, --output DIRECTORY (required)
|
209
|
+
Specify the output directory
|
210
|
+
```
|
211
|
+
|
212
|
+
The flags's value will be available to you as `${args[--output]}` in your
|
213
|
+
bash function (regardless of whether the user provided ut with the long or
|
214
|
+
short form).
|
215
|
+
|
216
|
+
```yaml
|
217
|
+
# The long form of the flag.
|
218
|
+
long: --output
|
219
|
+
|
220
|
+
# The short form of the flag.
|
221
|
+
short: -o
|
222
|
+
|
223
|
+
# The text to display when using --help
|
224
|
+
# This can have multiple lines, but it is recommended to keep lines shorter
|
225
|
+
# than ~70 characters, to avoid text wrapping in narrower terminals.
|
226
|
+
help: Specify the output directory
|
227
|
+
|
228
|
+
# If the flag requires an argument, specify its name here.
|
229
|
+
arg: directory
|
230
|
+
|
231
|
+
# Specify if this flag is required.
|
232
|
+
required: true
|
233
|
+
```
|
234
|
+
|
44
235
|
Contributing / Support
|
45
236
|
--------------------------------------------------
|
46
237
|
|
47
238
|
If you experience any issue, have a question or a suggestion, or if you wish
|
48
239
|
to contribute, feel free to [open an issue][issues].
|
240
|
+
|
241
|
+
[issues]: https://github.com/DannyBen/bashly/issues
|
242
|
+
|
data/lib/bashly.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mister_bin'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Bashly
|
4
5
|
module Commands
|
@@ -47,6 +48,7 @@ module Bashly
|
|
47
48
|
def create_master_script
|
48
49
|
master_script = command.render 'master_script'
|
49
50
|
File.write master_script_path, master_script
|
51
|
+
FileUtils.chmod "+x", master_script_path
|
50
52
|
say "created !txtgrn!#{master_script_path}"
|
51
53
|
end
|
52
54
|
|
data/lib/bashly/version.rb
CHANGED
@@ -4,8 +4,8 @@ if [[ $1 && $1 != -* ]]; then
|
|
4
4
|
args[<%= arg.name %>]=$1
|
5
5
|
shift
|
6
6
|
else
|
7
|
-
echo missing required argument: <%= arg.name.upcase %>
|
8
|
-
echo Usage: <%= usage_string %>
|
7
|
+
echo "missing required argument: <%= arg.name.upcase %>"
|
8
|
+
echo "Usage: <%= usage_string %>"
|
9
9
|
exit 1
|
10
10
|
fi
|
11
11
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# :command.required_flags_filter
|
2
|
+
<%- if required_flags.any? -%>
|
3
|
+
argstring="$*"
|
4
|
+
<%- end -%>
|
2
5
|
<%- required_flags.each do |flag| -%>
|
3
|
-
if [[ <%= flag.aliases.map { |a| "
|
6
|
+
if [[ <%= flag.aliases.map { |a| %Q["$argstring" != *#{a}*] }.join " && " %> ]]; then
|
4
7
|
echo "missing required flag: <%= flag.usage_string %>"
|
5
8
|
exit 1
|
6
9
|
fi
|
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.1.
|
4
|
+
version: 0.1.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: 2019-11-
|
11
|
+
date: 2019-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mister_bin
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.7'
|
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.
|
40
|
+
version: '0.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: requires
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/bashly/models/base.rb
|
76
76
|
- lib/bashly/models/command.rb
|
77
77
|
- lib/bashly/models/flag.rb
|
78
|
+
- lib/bashly/polyfills/hash.rb
|
78
79
|
- lib/bashly/settings.rb
|
79
80
|
- lib/bashly/templates/bashly.yml
|
80
81
|
- lib/bashly/templates/minimal.yml
|