bashly 0.6.3 → 0.6.4

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: 01c46120b6cecba45cf9b55dd726ce4b66888ba3fc11d3383557a554ac51b154
4
- data.tar.gz: 9682934a468d1624d05924f4ca5bd76d6438c26853fed1ad8098865dae669bc2
3
+ metadata.gz: 650f456561f180e0a39b2e6e0c66f6c5913438ac6301d44bff064470d602daba
4
+ data.tar.gz: 2f64d00edb50ce738d506568600d8b73b898aad6563990460a80a52d912a6e66
5
5
  SHA512:
6
- metadata.gz: bb068fa1b263a1f820910b548cd48fde9cc1ae8607c50eea381361f9cbfe952581a4e1c9e54ac31e20a96c6ccba876d2a58b2f0ec6e8a59c3f8a467fbe0bde43
7
- data.tar.gz: 653410059e779fffdf9aa28d8c23a0a2cc8d3ba0a7911651deaf2669fc1b4d744dc3a3824124ba79140813d331510ec14a1b47f852049c305ab47fe55fe9c89d
6
+ metadata.gz: 70427709c22c05bcfdfadb1daafaea8c87c5854b03488913c916ffb29861521c853eb5392f22c0c79b7bdc8fe359fc55389c0d6f0540493c250dd6ba1f7d79b5
7
+ data.tar.gz: 2b2aa5dc0525edc81ce3c023583b0d829907de9e1656a00fdb37d6cd87e0b4ab788e70e71fe51763a661006f8ce8fdf950a7c3e7ffcce095edec5cc799e942ed
data/README.md CHANGED
@@ -3,22 +3,66 @@
3
3
 
4
4
  # Bashly - Bash CLI Framework and Generator
5
5
 
6
- Create beautiful bash scripts from simple YAML configuration
6
+ Create feature-rich bash scripts using simple YAML configuration
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/bashly.svg)](https://badge.fury.io/rb/bashly)
9
9
  [![Build Status](https://github.com/DannyBen/bashly/workflows/Test/badge.svg)](https://github.com/DannyBen/bashly/actions?query=workflow%3ATest)
10
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/8cf89047e50ca601e431/maintainability)](https://codeclimate.com/github/DannyBen/bashly/maintainability)
11
11
 
12
+ ## [bashly.dannyb.co](https://bashly.dannyb.co)
13
+
12
14
  ---
13
15
 
14
16
  ![demo](demo/cast.svg)
15
17
 
16
18
  </div>
17
19
 
20
+ Bashly is a command line application (written in Ruby) that lets you
21
+ generate feature-rich bash command line tools.
22
+
23
+ Bashly lets you focus on your specific code, without worrying about command line
24
+ argument parsing, usage texts, error messages and other functions that are
25
+ usually handled by a framework in any other programming language.
26
+
27
+ It is available both as a [ruby gem](https://rubygems.org/gems/bashly) and as
28
+ a [docker image](https://hub.docker.com/r/dannyben/bashly).
29
+
30
+
18
31
  ## Documentation
19
32
 
20
- Visit the [Bashly Documentation][docs] site.
33
+ - [Bashly Homepage][docs]
34
+ - [Examples][examples]
35
+
36
+ ## How it works
37
+
38
+ 1. You provide a YAML configuration file, describing commands, sub-commands,
39
+ arguments, and flags. Running `bashly init` creates an initial sample YAML
40
+ file for you ([example](https://github.com/DannyBen/bashly/tree/master/examples/minimal#bashlyyml)).
41
+ 2. Bashly then automatically generates a bash script (when you run
42
+ `bashly generate`) that can parse and validate user input, provide help
43
+ messages, and run your code for each command ([example](https://github.com/DannyBen/bashly/blob/master/examples/minimal/download)).
44
+ 3. Your code for each command is kept in a separate file, and can be merged
45
+ again if you change it ([example](https://github.com/DannyBen/bashly/blob/master/examples/minimal/src/root_command.sh)).
46
+
47
+ ## Features
48
+
49
+ Bashly is responsible for:
21
50
 
51
+ - Generating a **single, standalone bash script**.
52
+ - Generating **usage texts** and help screens, showing your tool's arguments, flags and commands (works for sub-commands also).
53
+ - Parsing the user's command line and extracting:
54
+ - Optional or required **positional arguments**.
55
+ - Optional or required **option flags** (with or without flag arguments).
56
+ - **Commands** (and sub-commands).
57
+ - Standard flags (like **--help** and **--version**).
58
+ - Preventing your script from running unless the command line is valid.
59
+ - Providing you with a place to input your code for each of the functions your tool performs, and merging it back to the final script.
60
+ - Providing you with additional (optional) framework-style, standard library functions:
61
+ - **Color output**.
62
+ - **Config file management** (INI format).
63
+ - **YAML parsing**.
64
+ - **Bash completions**.
65
+ - and more.
22
66
 
23
67
  ## Contributing / Support
24
68
 
@@ -29,4 +73,5 @@ to contribute, feel free to [open an issue][issues].
29
73
 
30
74
  [issues]: https://github.com/DannyBen/bashly/issues
31
75
  [docs]: https://bashly.dannyb.co/
76
+ [examples]: https://github.com/DannyBen/bashly/tree/master/examples#bashly-examples
32
77
 
@@ -5,7 +5,7 @@ module Bashly
5
5
 
6
6
  # Returns the name to be used as an action.
7
7
  # - If it is the root command, the action is "root"
8
- # - Else, it is all the parents, except the first tone (root) joined
8
+ # - Else, it is all the parents, except the first one (root) joined
9
9
  # by space. For example, for a command like "docker container run"
10
10
  # the action name is "container run".
11
11
  def action_name
@@ -54,6 +54,17 @@ module Bashly
54
54
  end
55
55
  end
56
56
 
57
+ # Returns true if catch_all is required
58
+ def catch_all_required?
59
+ catch_all.is_a?(Hash) and catch_all['required']
60
+ end
61
+
62
+ # Returns a string suitable for catch_all Usage pattern
63
+ def catch_all_usage
64
+ return nil unless catch_all
65
+ catch_all_required? ? catch_all_label : "[#{catch_all_label}]"
66
+ end
67
+
57
68
  # Returns only the names of the Commands
58
69
  def command_names
59
70
  commands.map &:name
@@ -190,7 +201,7 @@ module Bashly
190
201
  result << arg.usage_string
191
202
  end
192
203
  result << "[options]" unless flags.empty?
193
- result << "[#{catch_all_label}]" if catch_all
204
+ result << catch_all_usage if catch_all
194
205
  result.join " "
195
206
  end
196
207
 
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -0,0 +1,7 @@
1
+ # :command.catch_all_filter
2
+ <%- if catch_all_required? -%>
3
+ if [[ ${#other_args[@]} -eq 0 ]]; then
4
+ printf "<%= strings[:missing_required_argument] % { arg: catch_all_label, usage: usage_string } %>\n"
5
+ exit 1
6
+ fi
7
+ <%- end -%>
@@ -16,7 +16,7 @@ case "$1" in
16
16
  <%- end -%>
17
17
  long_usage=yes
18
18
  <%= function_name %>_usage
19
- exit 1
19
+ exit
20
20
  ;;
21
21
 
22
22
  esac
@@ -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(:catch_all_filter).indent 2 %>
14
15
  <%= render(:default_assignments).indent 2 %>
15
16
  <%= render(:whitelist_filter).indent 2 %>
16
17
  }
data/lib/bashly.rb CHANGED
@@ -5,7 +5,6 @@ if ENV['BYEBUG']
5
5
  require 'lp'
6
6
  end
7
7
 
8
- requires 'bashly/polyfills'
9
8
  requires 'bashly/concerns'
10
9
 
11
10
  requires 'bashly/settings'
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.3
4
+ version: 0.6.4
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-08-25 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -102,7 +102,6 @@ files:
102
102
  - lib/bashly/models/environment_variable.rb
103
103
  - lib/bashly/models/flag.rb
104
104
  - lib/bashly/models/script.rb
105
- - lib/bashly/polyfills/hash.rb
106
105
  - lib/bashly/settings.rb
107
106
  - lib/bashly/templates/bashly.yml
108
107
  - lib/bashly/templates/lib/colors.sh
@@ -113,6 +112,7 @@ files:
113
112
  - lib/bashly/templates/strings.yml
114
113
  - lib/bashly/version.rb
115
114
  - lib/bashly/views/argument/usage.erb
115
+ - lib/bashly/views/command/catch_all_filter.erb
116
116
  - lib/bashly/views/command/command_fallback.erb
117
117
  - lib/bashly/views/command/command_filter.erb
118
118
  - lib/bashly/views/command/command_functions.erb
@@ -1,12 +0,0 @@
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
11
-
12
- # :nocov: