Skip to content

Commit

Permalink
- Check output with shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed May 21, 2024
1 parent a0c3a62 commit 3f7ae7e
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 54 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ jobs:
- name: Install OS dependencies
run: sudo apt-get -y install libyaml-dev

# Rush needed for easy installation of stuff
- name: Install rush
run: curl -Ls http://get.dannyb.co/rush/setup | bash

- name: Connect rush repo
run: rush clone dannyben --shallow --default

- name: Install shfmt
run: rush get shfmt

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mygit status:
- --help
- --verbose
- --branch
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)

mygit init:
- --bare
Expand Down Expand Up @@ -169,7 +169,7 @@ branches to your suggestions, use the following:

```yaml
mygit:
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)
```

The `2> /dev/null` is used so that if the command is executed in a directory
Expand All @@ -186,10 +186,10 @@ mygit checkout:
- -b
mygit checkout*--branch:
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)
mygit checkout*-b:
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)
```

The above will suggest git branches for commands that end with `-b` or `--branch`.
Expand All @@ -202,7 +202,7 @@ mygit checkout:
- -b
mygit checkout*--branch: &branches
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)
mygit checkout*-b: *branches
```
Expand Down
2 changes: 1 addition & 1 deletion lib/completely/templates/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mygit status:
- --help
- --verbose
- --branch
- $(git branch 2> /dev/null)
- $(git branch 2>/dev/null)

mygit init:
- --bare
Expand Down
4 changes: 2 additions & 2 deletions lib/completely/templates/template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
% patterns.each do |pattern|
% next if pattern.empty?
<%= pattern.case_string %>)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen <%= pattern.compgen %> -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen <%= pattern.compgen %> -- "$cur")
;;

% end
esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F <%= function_name %> <%= command %>
complete -F <%= function_name %> <%= command %>

# ex: filetype=sh
10 changes: 5 additions & 5 deletions spec/approvals/cli/generated-script
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ _mygit_completions() {

case "$compline" in
'status'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")
;;

'commit'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _mygit_completions mygit
complete -F _mygit_completions mygit

# ex: filetype=sh
10 changes: 5 additions & 5 deletions spec/approvals/cli/generated-script-alt
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ _mycomps() {

case "$compline" in
'status'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mycomps_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mycomps_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")
;;

'commit'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mycomps_filter "--help --message --all -a --quiet -q")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mycomps_filter "--help --message --all -a --quiet -q")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mycomps_filter "--bare")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mycomps_filter "--bare")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mycomps_filter "--help --version status init commit")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mycomps_filter "--help --version status init commit")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _mycomps mygit
complete -F _mycomps mygit

# ex: filetype=sh
10 changes: 5 additions & 5 deletions spec/approvals/cli/generated-wrapped-script
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ give_comps() {
echo $''
echo $' case "$compline" in'
echo $' \'status\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'commit\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'init\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur")'
echo $' ;;'
echo $''
echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $''
echo $' COMP_WORDBREAKS="$original_comp_wordbreaks"'
echo $'} &&'
echo $'complete -F _mygit_completions mygit'
echo $' complete -F _mygit_completions mygit'
echo $''
echo $'# ex: filetype=sh'
}
10 changes: 5 additions & 5 deletions spec/approvals/cli/test/completely-tester-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ _mygit_completions() {

case "$compline" in
'status'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")
;;

'commit'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _mygit_completions mygit
complete -F _mygit_completions mygit

# ex: filetype=sh

Expand Down
10 changes: 5 additions & 5 deletions spec/approvals/cli/test/completely-tester-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ _mygit_completions() {

case "$compline" in
'status'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")
;;

'commit'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _mygit_completions mygit
complete -F _mygit_completions mygit

# ex: filetype=sh

Expand Down
10 changes: 5 additions & 5 deletions spec/approvals/cli/test/completely-tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ _mygit_completions() {

case "$compline" in
'status'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2> /dev/null)")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --verbose --branch $(git branch 2>/dev/null)")" -- "$cur")
;;

'commit'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_mygit_completions_filter "--help --message --all -a --quiet -q")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_mygit_completions_filter "--bare")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "--help --version status init commit")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _mygit_completions mygit
complete -F _mygit_completions mygit

# ex: filetype=sh

Expand Down
8 changes: 4 additions & 4 deletions spec/approvals/completions/function
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ send_completions() {
echo $''
echo $' case "$compline" in'
echo $' \'generate\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'init\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help")" -- "$cur")'
echo $' ;;'
echo $''
echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $''
echo $' COMP_WORDBREAKS="$original_comp_wordbreaks"'
echo $'} &&'
echo $'complete -F _completely_completions completely'
echo $' complete -F _completely_completions completely'
echo $''
echo $'# ex: filetype=sh'
}
8 changes: 4 additions & 4 deletions spec/approvals/completions/script
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ _completely_completions() {

case "$compline" in
'generate'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help --version init generate")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _completely_completions completely
complete -F _completely_completions completely

# ex: filetype=sh
6 changes: 3 additions & 3 deletions spec/approvals/completions/script-only-spaces
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ _completely_completions() {

case "$compline" in
'generate'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -W "$(_completely_completions_filter "--help --force")" -- "$cur")
;;

'init'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_completely_completions_filter "--help")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_completely_completions_filter "--help")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _completely_completions completely
complete -F _completely_completions completely

# ex: filetype=sh
5 changes: 5 additions & 0 deletions spec/completely/commands/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
expect { subject.execute %w[generate] }.to output_approval('cli/generate/no-args')
expect(`shellcheck completely.bash 2>&1`).to be_empty
end

it 'generates a shfmt compliant script', :focus do
expect { subject.execute %w[generate] }.to output_approval('cli/generate/no-args')
expect(`shfmt -d -i 2 -ci completely.bash 2>&1`).to be_empty
end
end

context 'with CONFIG_PATH' do
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/tester/default.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ _cli_completions() {

case "$compline" in
'command childcommand'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--quiet --verbose -q -v")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--quiet --verbose -q -v")" -- "$cur")
;;

'command subcommand'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --quiet")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --quiet")" -- "$cur")
;;

'command'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "subcommand childcommand")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "subcommand childcommand")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version command conquer")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version command conquer")" -- "$cur")
;;

esac

COMP_WORDBREAKS="$original_comp_wordbreaks"
} &&
complete -F _cli_completions cli
complete -F _cli_completions cli

# ex: filetype=sh

0 comments on commit 3f7ae7e

Please sign in to comment.