bashly 1.2.12 → 1.3.1
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.
- checksums.yaml +4 -4
- data/README.md +6 -10
- data/lib/bashly/commands/render.rb +3 -2
- data/lib/bashly/completions/bashly-completions.bash +1 -1
- data/lib/bashly/extensions/string.rb +2 -2
- data/lib/bashly/libraries/hooks/before.sh +6 -3
- data/lib/bashly/libraries/hooks/initialize.sh +4 -0
- data/lib/bashly/libraries/libraries.yml +13 -0
- data/lib/bashly/libraries/render/mandoc/summary.txt +1 -1
- data/lib/bashly/libraries/render/markdown/summary.txt +1 -1
- data/lib/bashly/libraries/render/markdown_github/README.md +37 -0
- data/lib/bashly/libraries/render/markdown_github/markdown.gtx +190 -0
- data/lib/bashly/libraries/render/markdown_github/render.rb +23 -0
- data/lib/bashly/libraries/render/markdown_github/summary.txt +1 -0
- data/lib/bashly/libraries/settings/settings.yml +18 -8
- data/lib/bashly/libraries/stacktrace/stacktrace.sh +29 -0
- data/lib/bashly/libraries/strings/strings.yml +1 -1
- data/lib/bashly/libraries/validations/validate_dir_exists.sh +3 -1
- data/lib/bashly/libraries/validations/validate_file_exists.sh +3 -1
- data/lib/bashly/libraries/validations/validate_integer.sh +4 -2
- data/lib/bashly/libraries/validations/validate_not_empty.sh +3 -1
- data/lib/bashly/script/command.rb +2 -2
- data/lib/bashly/script/formatter.rb +44 -0
- data/lib/bashly/script/wrapper.rb +7 -1
- data/lib/bashly/settings.rb +5 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/README.md +1 -1
- data/lib/bashly/views/argument/validations.gtx +6 -4
- data/lib/bashly/views/command/master_script.gtx +2 -4
- data/lib/bashly/views/command/start.gtx +5 -0
- data/lib/bashly/views/wrapper/bash3_bouncer.gtx +5 -2
- data/lib/bashly.rb +1 -1
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ac473fa7be8511393fdc443f632ee359f044083935f1db09e28382ade67a132
|
4
|
+
data.tar.gz: 2fdc90bedee600c6a5be795a48580f9db672116f90b8ce1d97c068d932161522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1573a20f34fb2e5651be13ff24bc8af687ab81a53750a97fd411d18cf08320af85d6480dccaf2f786fff82394803dbdfaead78ac5a2cc200ccd7e338d6b6b55
|
7
|
+
data.tar.gz: 630d815115bfdb10796621795c800594cf1a7953f74e9c6bafda8baad47f54bf57095c1dda34fbea9fbe4d3eede6ccdb32aa056b3da9fe15bd5839026af5cbef
|
data/README.md
CHANGED
@@ -5,10 +5,6 @@
|
|
5
5
|
|
6
6
|
Create feature-rich bash scripts using simple YAML configuration
|
7
7
|
|
8
|
-
[](https://badge.fury.io/rb/bashly)
|
9
|
-
[](https://github.com/DannyBen/bashly/actions?query=workflow%3ATest)
|
10
|
-
[](https://codeclimate.com/github/DannyBen/bashly/maintainability)
|
11
|
-
|
12
8
|
## [bashly.dev](https://bashly.dev)
|
13
9
|
|
14
10
|
---
|
@@ -36,12 +32,12 @@ a [docker image](https://hub.docker.com/r/dannyben/bashly).
|
|
36
32
|
|
37
33
|
1. You provide a YAML configuration file, describing commands, sub-commands,
|
38
34
|
arguments, and flags. Running `bashly init` creates an initial sample YAML
|
39
|
-
file for you ([example](https://github.com/
|
35
|
+
file for you ([example](https://github.com/bashly-framework/bashly/tree/master/examples/minimal#bashlyyml)).
|
40
36
|
2. Bashly then automatically generates a bash script (when you run
|
41
37
|
`bashly generate`) that can parse and validate user input, provide help
|
42
38
|
messages, and run your code for each command.
|
43
39
|
3. Your code for each command is kept in a separate file, and can be merged
|
44
|
-
again if you change it ([example](https://github.com/
|
40
|
+
again if you change it ([example](https://github.com/bashly-framework/bashly/blob/master/examples/minimal/src/root_command.sh)).
|
45
41
|
|
46
42
|
## Features
|
47
43
|
|
@@ -74,8 +70,8 @@ to contribute, feel free to [open an issue][issues] or
|
|
74
70
|
Visit the *[How to contribute][contributing]* page for more information.
|
75
71
|
|
76
72
|
|
77
|
-
[issues]: https://github.com/
|
78
|
-
[discussions]: https://github.com/
|
73
|
+
[issues]: https://github.com/bashly-framework/bashly/issues
|
74
|
+
[discussions]: https://github.com/bashly-framework/bashly/discussions
|
79
75
|
[docs]: https://bashly.dev/
|
80
|
-
[examples]: https://github.com/
|
81
|
-
[contributing]: https://github.com/
|
76
|
+
[examples]: https://github.com/bashly-framework/bashly/tree/master/examples#bashly-examples
|
77
|
+
[contributing]: https://github.com/bashly-framework/bashly/blob/master/CONTRIBUTING.md#how-to-contribute
|
@@ -34,7 +34,8 @@ module Bashly
|
|
34
34
|
example 'bashly render --list'
|
35
35
|
example 'bashly render :markdown --about'
|
36
36
|
example 'bashly render :markdown docs --watch'
|
37
|
-
example 'bashly render :markdown docs --show "cli
|
37
|
+
example 'bashly render :markdown docs --show "cli download.md'
|
38
|
+
example 'bashly render :mandoc docs --show cli-download.1'
|
38
39
|
example 'bashly render /path/to/templates ./out_path'
|
39
40
|
|
40
41
|
attr_reader :watching, :target, :source
|
@@ -51,7 +52,7 @@ module Bashly
|
|
51
52
|
|
52
53
|
def show_list
|
53
54
|
RenderSource.internal.each_value do |source|
|
54
|
-
say "g`:#{source.selector.to_s.ljust
|
55
|
+
say "g`:#{source.selector.to_s.ljust 16}` #{source.summary}"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# bashly completion -*- shell-script -*-
|
2
2
|
|
3
3
|
# This bash completions script was generated by
|
4
|
-
# completely (https://github.com/
|
4
|
+
# completely (https://github.com/bashly-framework/completely)
|
5
5
|
# Modifying it manually is not recommended
|
6
6
|
|
7
7
|
_bashly_completions_filter() {
|
@@ -1,8 +1,11 @@
|
|
1
1
|
## before hook
|
2
2
|
##
|
3
|
-
## Any code here will be placed inside
|
4
|
-
## before running any command (but after processing
|
3
|
+
## Any code here will be placed inside the `before_hook()` function and called
|
4
|
+
## before running any command (but after argument processing is complete).
|
5
|
+
##
|
6
|
+
## - The processed args are available to you here as `args` and `extra_args`
|
7
|
+
## - The raw input array is also available in read-only mode as `input`
|
5
8
|
##
|
6
9
|
## You can safely delete this file if you do not need it.
|
7
10
|
echo "==[ Before Hook Called ]=="
|
8
|
-
inspect_args
|
11
|
+
inspect_args
|
@@ -3,4 +3,8 @@
|
|
3
3
|
## Any code here will be placed inside the `initialize()` function and called
|
4
4
|
## before running anything else.
|
5
5
|
##
|
6
|
+
## The original command line arguments are available in the `command_line_args`
|
7
|
+
## array. You can modify or override the input before it is processed further,
|
8
|
+
## though this is usually only needed for advanced use cases.
|
9
|
+
##
|
6
10
|
## You can safely delete this file if you do not need it.
|
@@ -102,6 +102,19 @@ settings:
|
|
102
102
|
- source: "settings/settings.yml"
|
103
103
|
target: "settings.yml"
|
104
104
|
|
105
|
+
stacktrace:
|
106
|
+
help: Add a function that shows stacktrace on error.
|
107
|
+
files:
|
108
|
+
- source: "stacktrace/stacktrace.sh"
|
109
|
+
target: "%{user_lib_dir}/stacktrace.%{user_ext}"
|
110
|
+
post_install_message: |
|
111
|
+
The stacktrace function is designed to be called automatically on error.
|
112
|
+
|
113
|
+
To enable this functionality, call g`enable_stacktrace` in your
|
114
|
+
g`src/initialize.sh`. You may run the following command to add this file:
|
115
|
+
|
116
|
+
m`$ bashly add hooks`
|
117
|
+
|
105
118
|
strings:
|
106
119
|
help: Copy an additional configuration file to your project, allowing you to customize all the tips and error strings.
|
107
120
|
files:
|
@@ -1 +1 @@
|
|
1
|
-
Render man pages
|
1
|
+
Render man pages
|
@@ -1 +1 @@
|
|
1
|
-
Render markdown documents
|
1
|
+
Render markdown documents
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Render GitHub markdown
|
2
|
+
|
3
|
+
Render GitHub-compatible markdown documents for your script.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```bash
|
8
|
+
# Generate all documents to the ./docs directory
|
9
|
+
$ bashly render :markdown_github docs
|
10
|
+
|
11
|
+
# Generate on change, and show one of the files
|
12
|
+
$ bashly render :markdown_github docs --watch --show index.md
|
13
|
+
```
|
14
|
+
|
15
|
+
The differences between this template and the `:markdown` template are:
|
16
|
+
|
17
|
+
- Links to sub-command files include the `.md` extension.
|
18
|
+
- The main file is named `README.md` instead of `index.md`.
|
19
|
+
|
20
|
+
## Supported custom definitions
|
21
|
+
|
22
|
+
Add these definitions to your `bashly.yml` to render them in your
|
23
|
+
markdown:
|
24
|
+
|
25
|
+
### Footer: `x_markdown_footer`
|
26
|
+
|
27
|
+
Add additional sections to your man pages. This field is expected
|
28
|
+
to be in markdown format.
|
29
|
+
|
30
|
+
#### Example
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
x_markdown_footer: |-
|
34
|
+
# ISSUE TRACKER
|
35
|
+
|
36
|
+
Report issues at <https://github.com/lanalang/smallville>
|
37
|
+
```
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# === Header
|
2
|
+
|
3
|
+
> # {{ full_name }}
|
4
|
+
>
|
5
|
+
> {{ help.for_markdown }}
|
6
|
+
>
|
7
|
+
|
8
|
+
attributes = version || alt.any? || default || extensible
|
9
|
+
|
10
|
+
if attributes
|
11
|
+
> | Attributes |
|
12
|
+
> |------------------|-------------
|
13
|
+
if version
|
14
|
+
> | Version: | {{ version }}
|
15
|
+
end
|
16
|
+
if alt.any?
|
17
|
+
> | Alias: | {{ alt.join ', ' }}
|
18
|
+
end
|
19
|
+
if default
|
20
|
+
> | Default Command: | ✓ Yes
|
21
|
+
end
|
22
|
+
if extensible
|
23
|
+
> | Extensible: | {{ extensible.is_a?(String) ? extensible : "✓ Yes" }}
|
24
|
+
end
|
25
|
+
>
|
26
|
+
end
|
27
|
+
|
28
|
+
# === Usage
|
29
|
+
|
30
|
+
> ## Usage
|
31
|
+
>
|
32
|
+
> ```bash
|
33
|
+
> {{ usage_string.for_markdown }}
|
34
|
+
> ```
|
35
|
+
>
|
36
|
+
|
37
|
+
# === Examples
|
38
|
+
|
39
|
+
if examples
|
40
|
+
> ## Examples
|
41
|
+
>
|
42
|
+
examples.each do |example|
|
43
|
+
> ```bash
|
44
|
+
> {{ example }}
|
45
|
+
> ```
|
46
|
+
>
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# === Dependencies
|
51
|
+
|
52
|
+
if dependencies.any?
|
53
|
+
> ## Dependencies
|
54
|
+
>
|
55
|
+
dependencies.each do |dependency|
|
56
|
+
> #### *{{ dependency.commands.join ', ' }}*
|
57
|
+
>
|
58
|
+
> {{ dependency.help&.for_markdown }}
|
59
|
+
>
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# === Environment Variables
|
64
|
+
|
65
|
+
if visible_environment_variables.any?
|
66
|
+
> ## Environment Variables
|
67
|
+
>
|
68
|
+
visible_environment_variables.each do |environment_variable|
|
69
|
+
attributes = environment_variable.required || environment_variable.default
|
70
|
+
|
71
|
+
> #### *{{ environment_variable.name.upcase }}*
|
72
|
+
>
|
73
|
+
> {{ environment_variable.help.for_markdown }}
|
74
|
+
>
|
75
|
+
|
76
|
+
if attributes
|
77
|
+
> | Attributes |
|
78
|
+
> |-----------------|-------------
|
79
|
+
if environment_variable.required
|
80
|
+
> | Required: | ✓ Yes
|
81
|
+
end
|
82
|
+
if environment_variable.default
|
83
|
+
> | Default Value: | {{ environment_variable.default }}
|
84
|
+
end
|
85
|
+
>
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# === Commands
|
91
|
+
|
92
|
+
if commands.any?
|
93
|
+
grouped_commands.each do |group, commands|
|
94
|
+
> ## {{ group.gsub(/:$/, '') }}
|
95
|
+
>
|
96
|
+
commands.each do |subcommand|
|
97
|
+
> - [{{ subcommand.name }}]({{ subcommand.full_name.gsub(' ', '%20') }}.md) - {{ subcommand.summary.for_markdown }}
|
98
|
+
end
|
99
|
+
>
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# === Arguments
|
104
|
+
|
105
|
+
if args.any?
|
106
|
+
> ## Arguments
|
107
|
+
>
|
108
|
+
args.each do |arg|
|
109
|
+
attributes = arg.required || arg.repeatable || arg.default || arg.allowed
|
110
|
+
|
111
|
+
> #### *{{ arg.name.upcase }}*
|
112
|
+
>
|
113
|
+
> {{ arg.help.for_markdown }}
|
114
|
+
>
|
115
|
+
|
116
|
+
if attributes
|
117
|
+
> | Attributes |
|
118
|
+
> |-----------------|-------------
|
119
|
+
if arg.required
|
120
|
+
> | Required: | ✓ Yes
|
121
|
+
end
|
122
|
+
if arg.repeatable
|
123
|
+
> | Repeatable: | ✓ Yes
|
124
|
+
end
|
125
|
+
if arg.default
|
126
|
+
> | Default Value: | {{ arg.default }}
|
127
|
+
end
|
128
|
+
if arg.allowed
|
129
|
+
> | Allowed Values: | {{ arg.allowed.join(', ') }}
|
130
|
+
end
|
131
|
+
>
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
if catch_all.label && catch_all.help
|
136
|
+
> #### *{{ catch_all.label }}*
|
137
|
+
>
|
138
|
+
> {{ catch_all.help&.for_markdown }}
|
139
|
+
>
|
140
|
+
if catch_all.required?
|
141
|
+
> | Attributes |
|
142
|
+
> |------------|-------------
|
143
|
+
> | Required: | ✓ Yes
|
144
|
+
>
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# === Flags
|
150
|
+
|
151
|
+
if flags.any?
|
152
|
+
> ## Options
|
153
|
+
>
|
154
|
+
flags.each do |flag|
|
155
|
+
attributes = flag.required || flag.repeatable || flag.default ||
|
156
|
+
flag.allowed || flag.conflicts || flag.needs
|
157
|
+
|
158
|
+
> #### *{{ flag.usage_string }}*
|
159
|
+
>
|
160
|
+
> {{ flag.help.for_markdown }}
|
161
|
+
>
|
162
|
+
|
163
|
+
if attributes
|
164
|
+
> | Attributes |
|
165
|
+
> |-----------------|-------------
|
166
|
+
if flag.required
|
167
|
+
> | Required: | ✓ Yes
|
168
|
+
end
|
169
|
+
if flag.repeatable
|
170
|
+
> | Repeatable: | ✓ Yes
|
171
|
+
end
|
172
|
+
if flag.default
|
173
|
+
> | Default Value: | {{ flag.default }}
|
174
|
+
end
|
175
|
+
if flag.allowed
|
176
|
+
> | Allowed Values: | {{ flag.allowed.join(', ') }}
|
177
|
+
end
|
178
|
+
if flag.conflicts
|
179
|
+
> | Conflicts With: | *{{ flag.conflicts.join(', ') }}*
|
180
|
+
end
|
181
|
+
if flag.needs
|
182
|
+
> | Needs: | *{{ flag.needs.join(', ') }}*
|
183
|
+
end
|
184
|
+
>
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
= x_markdown_footer&.for_manpage
|
190
|
+
>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# render script - markdown
|
2
|
+
require 'gtx'
|
3
|
+
|
4
|
+
# for previewing only (not needed for rendering)
|
5
|
+
require 'tty-markdown'
|
6
|
+
|
7
|
+
# Load the GTX template
|
8
|
+
template = "#{source}/markdown.gtx"
|
9
|
+
gtx = GTX.load_file template
|
10
|
+
|
11
|
+
# Render the file for the main command
|
12
|
+
save "#{target}/README.md", gtx.parse(command)
|
13
|
+
|
14
|
+
# Render a file for each subcommand
|
15
|
+
command.deep_commands.reject(&:private).each do |subcommand|
|
16
|
+
save "#{target}/#{subcommand.full_name}.md", gtx.parse(subcommand)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Show one of the files if requested
|
20
|
+
if show
|
21
|
+
file = "#{target}/#{show}"
|
22
|
+
puts TTY::Markdown.parse_file(file) if File.exist?(file)
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Render GitHub-compatible markdown documents
|
@@ -41,16 +41,26 @@ partials_extension: sh
|
|
41
41
|
#-------------------------------------------------------------------------------
|
42
42
|
|
43
43
|
# Configure the bash options that will be added to the initialize function:
|
44
|
-
# strict: true Bash strict mode (set -euo pipefail)
|
45
|
-
# strict: false Only exit on errors (set -e)
|
46
|
-
# strict: '' Do not add any 'set' directive
|
47
|
-
# strict: <string> Add any other custom 'set' directive
|
44
|
+
# strict: true # Bash strict mode (set -euo pipefail)
|
45
|
+
# strict: false # Only exit on errors (set -e)
|
46
|
+
# strict: '' # Do not add any 'set' directive
|
47
|
+
# strict: <string> # Add any other custom 'set' directive
|
48
48
|
strict: false
|
49
49
|
|
50
50
|
# When true, the generated script will use tab indentation instead of spaces
|
51
51
|
# (every 2 leading spaces will be converted to a tab character)
|
52
52
|
tab_indent: false
|
53
53
|
|
54
|
+
# Choose a post-processor for the generated script:
|
55
|
+
# formatter: internal # Use Bashly's internal formatter (compacts newlines)
|
56
|
+
# formatter: external # Run the external command `shfmt --case-indent --indent 2`
|
57
|
+
# formatter: none # Disable formatting entirely
|
58
|
+
# formatter: <string> # Use a custom shell command to format the script.
|
59
|
+
# # The command will receive the script via stdin and
|
60
|
+
# # must output the result to stdout.
|
61
|
+
# # Example: shfmt --minify
|
62
|
+
formatter: internal
|
63
|
+
|
54
64
|
|
55
65
|
#-------------------------------------------------------------------------------
|
56
66
|
# INTERFACE OPTIONS
|
@@ -100,10 +110,10 @@ env: development
|
|
100
110
|
|
101
111
|
# Tweak the script output by enabling or disabling some script output.
|
102
112
|
# These options accept one of the following strings:
|
103
|
-
# - production render this feature only when env == production
|
104
|
-
# - development render this feature only when env == development
|
105
|
-
# - always render this feature in any environment
|
106
|
-
# - never do not render this feature
|
113
|
+
# - production # render this feature only when env == production
|
114
|
+
# - development # render this feature only when env == development
|
115
|
+
# - always # render this feature in any environment
|
116
|
+
# - never # do not render this feature
|
107
117
|
enable_header_comment: always
|
108
118
|
enable_bash3_bouncer: always
|
109
119
|
enable_view_markers: development
|
@@ -0,0 +1,29 @@
|
|
1
|
+
## Stack trace functions [@bashly-upgrade stacktrace]
|
2
|
+
## This file is a part of Bashly standard library
|
3
|
+
##
|
4
|
+
## Usage:
|
5
|
+
## This function is designed to be called on error.
|
6
|
+
##
|
7
|
+
## To enable this functionality, call `enable_stacktrace` in your
|
8
|
+
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
|
9
|
+
##
|
10
|
+
enable_stacktrace() {
|
11
|
+
trap 'stacktrace' ERR
|
12
|
+
set -o errtrace
|
13
|
+
set -o errexit
|
14
|
+
}
|
15
|
+
|
16
|
+
stacktrace() {
|
17
|
+
local exit_status="$?"
|
18
|
+
local i=0
|
19
|
+
local caller_output line func file
|
20
|
+
|
21
|
+
printf "%s:%s in \`%s\`: %s\n" "${BASH_SOURCE[0]}" "${BASH_LINENO[0]}" "${FUNCNAME[1]}" "$BASH_COMMAND"
|
22
|
+
printf "\nStack trace:\n"
|
23
|
+
while caller_output="$(caller $i)"; do
|
24
|
+
read -r line func file <<<"$caller_output"
|
25
|
+
printf "\tfrom %s:%s in \`%s\`\n" "$file" "$line" "$func"
|
26
|
+
i=$((i + 1))
|
27
|
+
done
|
28
|
+
exit "$exit_status"
|
29
|
+
} >&2
|
@@ -40,6 +40,6 @@ examples_caption_on_error: 'examples:'
|
|
40
40
|
disallowed_flag: "%{name} must be one of: %{allowed}"
|
41
41
|
disallowed_argument: "%{name} must be one of: %{allowed}"
|
42
42
|
disallowed_environment_variable: "%{name} environment variable must be one of: %{allowed}"
|
43
|
-
unsupported_bash_version: "bash version 4 or higher is required"
|
43
|
+
unsupported_bash_version: "bash version 4.2 or higher is required"
|
44
44
|
validation_error: "validation error in %s:\\n%s"
|
45
45
|
environment_variable_validation_error: "validation error in environment variable %s:\\n%s"
|
@@ -87,8 +87,8 @@ module Bashly
|
|
87
87
|
# flag with arg that is defined as unique
|
88
88
|
def has_unique_args_or_flags?
|
89
89
|
deep_commands(include_self: true).each do |command|
|
90
|
-
return true if command.args.
|
91
|
-
command.flags.
|
90
|
+
return true if command.args.any?(&:unique) ||
|
91
|
+
command.flags.any?(&:unique)
|
92
92
|
end
|
93
93
|
false
|
94
94
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
module Bashly
|
5
|
+
module Script
|
6
|
+
class Formatter
|
7
|
+
attr_reader :script, :mode
|
8
|
+
|
9
|
+
def initialize(script, mode: nil)
|
10
|
+
@script = script
|
11
|
+
@mode = mode&.to_s || 'internal'
|
12
|
+
end
|
13
|
+
|
14
|
+
def formatted_script
|
15
|
+
case mode
|
16
|
+
when 'internal' then script.gsub(/\s+\n/m, "\n\n")
|
17
|
+
when 'external' then shfmt_result
|
18
|
+
when 'none' then script
|
19
|
+
else custom_formatter_result mode
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def shfmt_result
|
26
|
+
custom_formatter_result %w[shfmt --case-indent --indent 2]
|
27
|
+
end
|
28
|
+
|
29
|
+
def custom_formatter_result(command)
|
30
|
+
command = Shellwords.split command if command.is_a? String
|
31
|
+
|
32
|
+
begin
|
33
|
+
output, error, status = Open3.capture3(*command, stdin_data: script)
|
34
|
+
rescue Errno::ENOENT
|
35
|
+
raise Error, "Command not found: g`#{command.first}`"
|
36
|
+
end
|
37
|
+
|
38
|
+
raise Error, "Failed running g`#{Shellwords.join command}`:\n\n#{error}" unless status.success?
|
39
|
+
|
40
|
+
output
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -23,7 +23,13 @@ module Bashly
|
|
23
23
|
[header, body]
|
24
24
|
end
|
25
25
|
|
26
|
-
result.join("\n")
|
26
|
+
clean_code result.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
def clean_code(script)
|
30
|
+
result = script.remove_private_comments
|
31
|
+
formatter = Formatter.new result, mode: Settings.formatter
|
32
|
+
formatter.formatted_script
|
27
33
|
end
|
28
34
|
|
29
35
|
def header
|
data/lib/bashly/settings.rb
CHANGED
@@ -15,6 +15,7 @@ module Bashly
|
|
15
15
|
:enable_inspect_args,
|
16
16
|
:enable_sourcing,
|
17
17
|
:enable_view_markers,
|
18
|
+
:formatter,
|
18
19
|
:function_names,
|
19
20
|
:lib_dir,
|
20
21
|
:partials_extension,
|
@@ -86,6 +87,10 @@ module Bashly
|
|
86
87
|
@env = value&.to_sym
|
87
88
|
end
|
88
89
|
|
90
|
+
def formatter
|
91
|
+
@formatter ||= get :formatter
|
92
|
+
end
|
93
|
+
|
89
94
|
def full_lib_dir
|
90
95
|
"#{source_dir}/#{lib_dir}"
|
91
96
|
end
|
data/lib/bashly/version.rb
CHANGED
data/lib/bashly/views/README.md
CHANGED
@@ -6,15 +6,17 @@ if validate
|
|
6
6
|
> values=''
|
7
7
|
> eval "values=(${args['{{ name }}']})"
|
8
8
|
> for value in "${values[@]}"; do
|
9
|
-
>
|
10
|
-
>
|
9
|
+
> validation_output="$(validate_{{ validate }} "$value")"
|
10
|
+
> if [[ -n "$validation_output" ]]; then
|
11
|
+
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$validation_output" >&2
|
11
12
|
> exit 1
|
12
13
|
> fi
|
13
14
|
> done
|
14
15
|
> fi
|
15
16
|
else
|
16
|
-
>
|
17
|
-
>
|
17
|
+
> validation_output="$(validate_{{ validate }} "${args['{{ name }}']:-}")"
|
18
|
+
> if [[ -v args['{{ name }}'] && -n "$validation_output" ]]; then
|
19
|
+
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$validation_output" >&2
|
18
20
|
> exit 1
|
19
21
|
> fi
|
20
22
|
>
|
@@ -15,11 +15,9 @@
|
|
15
15
|
>
|
16
16
|
if Settings.enabled? :sourcing
|
17
17
|
> if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
18
|
-
|
19
|
-
> {{ Settings.function_name :run }} "$@"
|
18
|
+
= render(:start).indent 2
|
20
19
|
> fi
|
21
20
|
else
|
22
|
-
|
23
|
-
> {{ Settings.function_name :run }} "$@"
|
21
|
+
= render :start
|
24
22
|
end
|
25
23
|
>
|
data/lib/bashly.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bashly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: colsole
|
@@ -225,7 +225,12 @@ files:
|
|
225
225
|
- lib/bashly/libraries/render/markdown/markdown.gtx
|
226
226
|
- lib/bashly/libraries/render/markdown/render.rb
|
227
227
|
- lib/bashly/libraries/render/markdown/summary.txt
|
228
|
+
- lib/bashly/libraries/render/markdown_github/README.md
|
229
|
+
- lib/bashly/libraries/render/markdown_github/markdown.gtx
|
230
|
+
- lib/bashly/libraries/render/markdown_github/render.rb
|
231
|
+
- lib/bashly/libraries/render/markdown_github/summary.txt
|
228
232
|
- lib/bashly/libraries/settings/settings.yml
|
233
|
+
- lib/bashly/libraries/stacktrace/stacktrace.sh
|
229
234
|
- lib/bashly/libraries/strings/strings.yml
|
230
235
|
- lib/bashly/libraries/test/approvals.bash
|
231
236
|
- lib/bashly/libraries/test/approve
|
@@ -248,6 +253,7 @@ files:
|
|
248
253
|
- lib/bashly/script/dependency.rb
|
249
254
|
- lib/bashly/script/environment_variable.rb
|
250
255
|
- lib/bashly/script/flag.rb
|
256
|
+
- lib/bashly/script/formatter.rb
|
251
257
|
- lib/bashly/script/introspection/arguments.rb
|
252
258
|
- lib/bashly/script/introspection/commands.rb
|
253
259
|
- lib/bashly/script/introspection/dependencies.rb
|
@@ -299,6 +305,7 @@ files:
|
|
299
305
|
- lib/bashly/views/command/required_flags_filter.gtx
|
300
306
|
- lib/bashly/views/command/root_command.gtx
|
301
307
|
- lib/bashly/views/command/run.gtx
|
308
|
+
- lib/bashly/views/command/start.gtx
|
302
309
|
- lib/bashly/views/command/usage.gtx
|
303
310
|
- lib/bashly/views/command/usage_args.gtx
|
304
311
|
- lib/bashly/views/command/usage_commands.gtx
|
@@ -327,14 +334,14 @@ files:
|
|
327
334
|
- lib/bashly/views/wrapper/bash3_bouncer.gtx
|
328
335
|
- lib/bashly/views/wrapper/header.gtx
|
329
336
|
- lib/bashly/views/wrapper/wrapper.gtx
|
330
|
-
homepage: https://github.com/
|
337
|
+
homepage: https://github.com/bashly-framework/bashly
|
331
338
|
licenses:
|
332
339
|
- MIT
|
333
340
|
metadata:
|
334
|
-
bug_tracker_uri: https://github.com/
|
335
|
-
changelog_uri: https://github.com/
|
341
|
+
bug_tracker_uri: https://github.com/bashly-framework/bashly/issues
|
342
|
+
changelog_uri: https://github.com/bashly-framework/bashly/blob/master/CHANGELOG.md
|
336
343
|
homepage_uri: https://bashly.dev/
|
337
|
-
source_code_uri: https://github.com/
|
344
|
+
source_code_uri: https://github.com/bashly-framework/bashly
|
338
345
|
rubygems_mfa_required: 'true'
|
339
346
|
rdoc_options: []
|
340
347
|
require_paths:
|
@@ -350,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
350
357
|
- !ruby/object:Gem::Version
|
351
358
|
version: '0'
|
352
359
|
requirements: []
|
353
|
-
rubygems_version: 3.6.
|
360
|
+
rubygems_version: 3.6.9
|
354
361
|
specification_version: 4
|
355
362
|
summary: Bash Command Line Tool Generator
|
356
363
|
test_files: []
|