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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4a6b6397239e1fc2b30d3f7cace59aa6bff9b305cfad97b43567dd49cd9eeb8
4
- data.tar.gz: 27eb14cc3d2f833dec9e218b3affc0e5d90fc0a4cb258e769127590b501a50ac
3
+ metadata.gz: e4dbc588718b280b13a81c8adbd2f4f86da7ec536baf3666d58592bfb2854ac5
4
+ data.tar.gz: 867936a132914810eb18cfb6b3ce10d36844c1e20ed348279374d4c2f2311bc7
5
5
  SHA512:
6
- metadata.gz: 0d907d581476cd66f71078319e1d1290f824d2fbbeac6315cd54988ce1068daf59c31e8ab383b498e7aae4955b7d3b2c225e3a3c701aead077527266d7e7dbe5
7
- data.tar.gz: 8ca10f7db1dd3f2fb03909e60b32f858220b85fd3a961d5c8c2b19e19026238fbce5a1c99ac66b8f3949e217ebdd0cd107cb430d74ff060f4e960f511ab9c6a5
6
+ metadata.gz: a1d3adacfcc29c6d74a0bbaa9ff339ce6150d1035588d2641f9094c486a572111c205e1d233bd9023e44e56c1f2c8e223488d34b5c3427f67b1291c7478598f5
7
+ data.tar.gz: 70884518d2343dd3915f03ecd0cf46809324c1a026fc28f9245ae57bd7e2587a5fb4a9a6e7a4cd5137b9d8110a28bb415658de48c7eb63d58e3b27bd4cb64403
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
- Bashly - Bbash CLI Generator
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
+
@@ -5,6 +5,7 @@ if ENV['BYEBUG']
5
5
  require 'lp'
6
6
  end
7
7
 
8
+ requires 'bashly/polyfills'
8
9
  requires 'bashly/settings'
9
10
  requires 'bashly/exceptions'
10
11
  requires 'bashly/concerns'
@@ -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
 
@@ -0,0 +1,10 @@
1
+ # :nocov:
2
+
3
+ # Required for Ruby < 2.4
4
+ if !Dir.respond_to? :empty?
5
+ class Dir
6
+ def self.empty?(path_name)
7
+ exist?(path_name) && (entries(path_name) - ['.', '..']).empty?
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # :command.inspect_args
2
2
  inspect_args() {
3
3
  echo args:
4
- for k in "${!args[@]}"; do echo "- \${args[$k]}" = ${args[$k]}; done
4
+ for k in "${!args[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
5
5
  }
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env bash
2
+ # This script was generated by bashly (https://github.com/DannyBen/bashly)
3
+ # Modifying it manually is not recommended
2
4
 
3
5
  <%= render :root_command if commands.empty? %>
4
6
  <%= render :version_command %>
@@ -8,10 +8,10 @@
8
8
  <%- condition = "elif" -%>
9
9
  <%- end -%>
10
10
  else
11
- echo invalid argument: $key
11
+ echo "invalid argument: $key"
12
12
  exit 1
13
13
  fi
14
14
  <%- else -%>
15
- echo invalid argument: $key
15
+ echo "invalid argument: $key"
16
16
  exit 1
17
17
  <%- end -%>
@@ -8,7 +8,7 @@ while [[ $# -gt 0 ]]; do
8
8
  <%- end -%>
9
9
 
10
10
  -* )
11
- echo invalid option: $key
11
+ echo "invalid option: $key"
12
12
  exit 1
13
13
  ;;
14
14
 
@@ -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| "$* != *#{a}*" }.join " && " %> ]]; then
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
@@ -1,4 +1,4 @@
1
1
  # :command.version_command
2
2
  version_command() {
3
- echo $version
3
+ echo "$version"
4
4
  }
@@ -6,7 +6,7 @@
6
6
  shift
7
7
  shift
8
8
  else
9
- echo <%= long %> requires an argument: <%= usage_string %>
9
+ echo "<%= long %> requires an argument: <%= usage_string %>"
10
10
  exit 1
11
11
  fi
12
12
  <%- else -%>
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.0
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-19 00:00:00.000000000 Z
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.5'
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.5'
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.6'
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.6'
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