Skip to content

Commit e9ae945

Browse files
authored
Merge pull request #314 from DannyBen/add/shfmt-compliance
Fix all shfmt offenses
2 parents 0458b30 + 6a06fcb commit e9ae945

20 files changed

+71
-40
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
env:
13-
LC_ALL: en_US.UTF-8 # consistent sort order
13+
# For consistent sort order
14+
LC_ALL: en_US.UTF-8
1415

1516
strategy:
1617
matrix: { ruby: ['2.7', '3.0', '3.1', 'head'] }
@@ -19,6 +20,7 @@ jobs:
1920
- name: Checkout code
2021
uses: actions/checkout@v3
2122

23+
# libyaml needed for Ruby's YAML library
2224
- name: Install OS dependencies
2325
run: sudo apt-get -y install libyaml-dev
2426

@@ -31,5 +33,34 @@ jobs:
3133
- name: Run tests
3234
run: bundle exec rspec
3335

36+
static_analysis:
37+
name: Static analysis of Example files
38+
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v3
44+
45+
# Rush needed for easy installation of latest shfmt
46+
- name: Install rush
47+
run: curl -Ls http://get.dannyb.co/rush/setup | bash
48+
49+
- name: Install shfmt
50+
run: rush snatch dannyben shfmt
51+
52+
# libyaml needed for Ruby's YAML library
53+
- name: Install OS dependencies
54+
run: sudo apt-get -y install libyaml-dev
55+
56+
- name: Setup Ruby
57+
uses: ruby/setup-ruby@v1
58+
with:
59+
ruby-version: '3.1'
60+
bundler-cache: true
61+
3462
- name: Run shellcheck tests
3563
run: bundle exec run shellcheck
64+
65+
- name: Run shfmt tests
66+
run: bundle exec run shfmt

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ usually handled by a framework in any other programming language.
2727
It is available both as a [ruby gem](https://rubygems.org/gems/bashly) and as
2828
a [docker image](https://hub.docker.com/r/dannyben/bashly).
2929

30-
3130
## Documentation
3231

3332
- [Bashly Homepage][docs]
@@ -49,6 +48,7 @@ a [docker image](https://hub.docker.com/r/dannyben/bashly).
4948
Bashly is responsible for:
5049

5150
- Generating a **single, standalone bash script**.
51+
- Generating a **human readable, shellcheck-compliant and shfmt-compliant script**.
5252
- Generating **usage texts** and help screens, showing your tool's arguments, flags and commands (works for sub-commands also).
5353
- Parsing the user's command line and extracting:
5454
- Optional or required **positional arguments**.
@@ -72,15 +72,12 @@ to contribute, feel free to [open an issue][issues] or
7272

7373
Visit the *[How to contribute][contributing]* page for more information.
7474

75-
7675
## Stargazers and Forkers
7776

7877
[![Stargazers repo roster for @DannyBen/bashly](https://reporoster.com/stars/DannyBen/bashly)](https://github.com/DannyBen/bashly/stargazers)
7978

8079
[![Forkers repo roster for @DannyBen/bashly](https://reporoster.com/forks/DannyBen/bashly)](https://github.com/DannyBen/bashly/network/members)
8180

82-
83-
8481
[issues]: https://github.com/DannyBen/bashly/issues
8582
[discussions]: https://github.com/DannyBen/bashly/discussions
8683
[docs]: https://bashly.dannyb.co/

Runfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ end
3535
help "Run shfmt checks on all examples"
3636
action :shfmt do
3737
Example.executables.each do |example|
38-
if File.exist? example
39-
success = system "shfmt -d -i 2 -ci #{example}"
40-
color = success ? 'txtgrn' : 'txtred'
41-
say "- shfmt !#{color}!#{example}"
42-
exit 1 unless success
43-
else
44-
say "- skip !txtcyn!#{example}"
38+
if example == 'examples/heredoc/cli' || !File.exist?(example)
39+
say "- skip !txtcyn!#{example}"
40+
next
4541
end
42+
43+
success = system "shfmt -d -i 2 -ci #{example}"
44+
color = success ? 'txtgrn' : 'txtred'
45+
say "- shfmt !#{color}!#{example}"
46+
exit 1 unless success
4647
end
4748
end
4849

examples/filters/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ commands:
5959
# Print an error string if docker is not running.
6060
# The script will automatically exit if this function prints anything.
6161
filter_docker_running() {
62-
docker info > /dev/null 2>&1 || echo "Docker must be running"
62+
docker info >/dev/null 2>&1 || echo "Docker must be running"
6363
}
6464

6565
# This is just a sample filter designed to always fail

examples/filters/src/lib/filters.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Print an error string if docker is not running.
77
# The script will automatically exit if this function prints anything.
88
filter_docker_running() {
9-
docker info > /dev/null 2>&1 || echo "Docker must be running"
9+
docker info >/dev/null 2>&1 || echo "Docker must be running"
1010
}
1111

1212
# This is just a sample filter designed to always fail

examples/heredoc-alt/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo "$text"
4040

4141
```bash
4242
message1() {
43-
cat << EOF
43+
cat <<EOF
4444
this is a
4545
multiline
4646
heredoc text

examples/heredoc-alt/src/lib/heredocs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
message1() {
2-
cat << EOF
2+
cat <<EOF
33
this is a
44
multiline
55
heredoc text

lib/bashly/views/command/command_fallback.gtx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ elsif extensible.is_a? String
2424
> printf "{{ strings[:invalid_command] }}\n" "$action" >&2
2525
> exit 1
2626
> fi
27+
> ;;
2728
>
2829

2930
elsif extensible
@@ -34,6 +35,7 @@ elsif extensible
3435
> printf "{{ strings[:invalid_command] }}\n" "$action" >&2
3536
> exit 1
3637
> fi
38+
> ;;
3739
>
3840

3941
else

lib/bashly/views/command/default_assignments.gtx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ if default_args.any? or default_flags.any?
22
= view_marker
33

44
default_args.each do |arg|
5-
> [[ -n ${args[{{ arg.name }}]:-} ]] || args[{{ arg.name }}]="{{ arg.default }}"
5+
> [[ -n ${args['{{ arg.name }}']:-} ]] || args['{{ arg.name }}']="{{ arg.default }}"
66
end
77

88
default_flags.each do |flag|
9-
> [[ -n ${args[{{ flag.long }}]:-} ]] || args[{{ flag.long }}]="{{ flag.default }}"
9+
> [[ -n ${args['{{ flag.long }}']:-} ]] || args['{{ flag.long }}']="{{ flag.default }}"
1010
end
1111

1212
>

lib/bashly/views/command/fixed_flags_filter.gtx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
> case "${1:-}" in
55

66
if root_command?
7-
= short_flag_exist?("-v") ? "--version)" : "--version | -v)".indent(4)
7+
= (short_flag_exist?("-v") ? "--version)" : "--version | -v)").indent(4)
88
> version_command
99
> exit
1010
> ;;
1111
>
1212
end
1313

14-
= short_flag_exist?("-h") ? "--help)" : "--help | -h)".indent(4)
14+
= (short_flag_exist?("-h") ? "--help)" : "--help | -h)").indent(4)
1515
> long_usage=yes
1616
> <%= function_name %>_usage
1717
> exit

0 commit comments

Comments
 (0)