From 3f7ae7e7b2e0e5fe7b2f65ee286ed35650e88c5d Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Tue, 21 May 2024 10:55:52 +0000 Subject: [PATCH] - Check output with shfmt --- .github/workflows/test.yml | 10 ++++++++++ README.md | 10 +++++----- lib/completely/templates/sample.yaml | 2 +- lib/completely/templates/template.erb | 4 ++-- spec/approvals/cli/generated-script | 10 +++++----- spec/approvals/cli/generated-script-alt | 10 +++++----- spec/approvals/cli/generated-wrapped-script | 10 +++++----- spec/approvals/cli/test/completely-tester-1.sh | 10 +++++----- spec/approvals/cli/test/completely-tester-2.sh | 10 +++++----- spec/approvals/cli/test/completely-tester.sh | 10 +++++----- spec/approvals/completions/function | 8 ++++---- spec/approvals/completions/script | 8 ++++---- spec/approvals/completions/script-only-spaces | 6 +++--- spec/completely/commands/generate_spec.rb | 5 +++++ spec/fixtures/tester/default.bash | 10 +++++----- 15 files changed, 69 insertions(+), 54 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce6243e..5accbd5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/README.md b/README.md index 893fd73..b5d0fa1 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ mygit status: - --help - --verbose - --branch -- $(git branch 2> /dev/null) +- $(git branch 2>/dev/null) mygit init: - --bare @@ -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 @@ -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`. @@ -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 ``` diff --git a/lib/completely/templates/sample.yaml b/lib/completely/templates/sample.yaml index 563add7..d900622 100644 --- a/lib/completely/templates/sample.yaml +++ b/lib/completely/templates/sample.yaml @@ -9,7 +9,7 @@ mygit status: - --help - --verbose - --branch -- $(git branch 2> /dev/null) +- $(git branch 2>/dev/null) mygit init: - --bare diff --git a/lib/completely/templates/template.erb b/lib/completely/templates/template.erb index ce593f4..aea1f2b 100644 --- a/lib/completely/templates/template.erb +++ b/lib/completely/templates/template.erb @@ -41,7 +41,7 @@ % 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 @@ -49,6 +49,6 @@ COMP_WORDBREAKS="$original_comp_wordbreaks" } && -complete -F <%= function_name %> <%= command %> + complete -F <%= function_name %> <%= command %> # ex: filetype=sh diff --git a/spec/approvals/cli/generated-script b/spec/approvals/cli/generated-script index e1fd6cc..8b170a0 100644 --- a/spec/approvals/cli/generated-script +++ b/spec/approvals/cli/generated-script @@ -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 diff --git a/spec/approvals/cli/generated-script-alt b/spec/approvals/cli/generated-script-alt index 0ed853b..1887993 100644 --- a/spec/approvals/cli/generated-script-alt +++ b/spec/approvals/cli/generated-script-alt @@ -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 diff --git a/spec/approvals/cli/generated-wrapped-script b/spec/approvals/cli/generated-wrapped-script index 13dbe15..7dde251 100644 --- a/spec/approvals/cli/generated-wrapped-script +++ b/spec/approvals/cli/generated-wrapped-script @@ -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' } \ No newline at end of file diff --git a/spec/approvals/cli/test/completely-tester-1.sh b/spec/approvals/cli/test/completely-tester-1.sh index 114e683..7050645 100644 --- a/spec/approvals/cli/test/completely-tester-1.sh +++ b/spec/approvals/cli/test/completely-tester-1.sh @@ -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 diff --git a/spec/approvals/cli/test/completely-tester-2.sh b/spec/approvals/cli/test/completely-tester-2.sh index 533d9f1..191d5aa 100644 --- a/spec/approvals/cli/test/completely-tester-2.sh +++ b/spec/approvals/cli/test/completely-tester-2.sh @@ -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 diff --git a/spec/approvals/cli/test/completely-tester.sh b/spec/approvals/cli/test/completely-tester.sh index 7b99691..294ed37 100644 --- a/spec/approvals/cli/test/completely-tester.sh +++ b/spec/approvals/cli/test/completely-tester.sh @@ -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 diff --git a/spec/approvals/completions/function b/spec/approvals/completions/function index c5bbc46..321e6ac 100644 --- a/spec/approvals/completions/function +++ b/spec/approvals/completions/function @@ -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' } \ No newline at end of file diff --git a/spec/approvals/completions/script b/spec/approvals/completions/script index 03d6b45..336a4cb 100644 --- a/spec/approvals/completions/script +++ b/spec/approvals/completions/script @@ -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 diff --git a/spec/approvals/completions/script-only-spaces b/spec/approvals/completions/script-only-spaces index 3f3ee6b..0b54cfe 100644 --- a/spec/approvals/completions/script-only-spaces +++ b/spec/approvals/completions/script-only-spaces @@ -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 diff --git a/spec/completely/commands/generate_spec.rb b/spec/completely/commands/generate_spec.rb index b535f21..bd1907e 100644 --- a/spec/completely/commands/generate_spec.rb +++ b/spec/completely/commands/generate_spec.rb @@ -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 diff --git a/spec/fixtures/tester/default.bash b/spec/fixtures/tester/default.bash index a945b82..7045747 100644 --- a/spec/fixtures/tester/default.bash +++ b/spec/fixtures/tester/default.bash @@ -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