-
Notifications
You must be signed in to change notification settings - Fork 2.3k
contrib/completions: sync bash completion with current CLI #5299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
immanuwell
wants to merge
1
commit into
opencontainers:main
Choose a base branch
from
immanuwell:fix-bash-completion-drift
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load helpers | ||
|
|
||
| function setup() { | ||
| requires root | ||
| } | ||
|
|
||
| function _get_comp_words_by_ref() { | ||
| local OPTIND _opt | ||
| while getopts "n:" _opt; do | ||
| : | ||
| done | ||
| shift $((OPTIND - 1)) | ||
|
|
||
| local cur_var=$1 | ||
| local prev_var=$2 | ||
| local words_var=$3 | ||
| local cword_var=$4 | ||
|
|
||
| printf -v "$cur_var" '%s' "${COMP_WORDS[COMP_CWORD]}" | ||
| if ((COMP_CWORD > 0)); then | ||
| printf -v "$prev_var" '%s' "${COMP_WORDS[COMP_CWORD - 1]}" | ||
| else | ||
| printf -v "$prev_var" '' | ||
| fi | ||
| eval "$words_var=()" | ||
| local i | ||
| for ((i = 0; i < ${#COMP_WORDS[@]}; i++)); do | ||
| eval "$words_var+=(\"\${COMP_WORDS[$i]}\")" | ||
| done | ||
| printf -v "$cword_var" '%s' "$COMP_CWORD" | ||
| } | ||
|
|
||
| function _filedir() { | ||
| : | ||
| } | ||
|
|
||
| function compopt() { | ||
| return 0 | ||
| } | ||
|
|
||
| function complete_runc() { | ||
| # shellcheck disable=SC1091 | ||
| source "${INTEGRATION_ROOT}/../../contrib/completions/bash/runc" | ||
|
|
||
| COMP_WORDS=("$@") | ||
| COMP_CWORD=$((${#COMP_WORDS[@]} - 1)) | ||
| COMPREPLY=() | ||
| _runc | ||
|
|
||
| printf '%s\n' "${COMPREPLY[@]}" | ||
| } | ||
|
|
||
| function contains_reply() { | ||
| local needle=$1 | ||
| shift | ||
|
|
||
| local reply | ||
| for reply in "$@"; do | ||
| if [ "$reply" = "$needle" ]; then | ||
| return 0 | ||
| fi | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| @test "top-level completion includes features" { | ||
| mapfile -t replies < <(complete_runc runc fe) | ||
|
|
||
| contains_reply "features" "${replies[@]}" | ||
| } | ||
|
|
||
| @test "delete completion suggests --force without a trailing comma" { | ||
| mapfile -t replies < <(complete_runc runc delete --f) | ||
|
|
||
| contains_reply "--force" "${replies[@]}" | ||
| run ! contains_reply "--force," "${replies[@]}" | ||
| } | ||
|
|
||
| @test "run completion matches supported flags" { | ||
| mapfile -t replies < <(complete_runc runc run --k) | ||
| contains_reply "--keep" "${replies[@]}" | ||
|
|
||
| mapfile -t replies < <(complete_runc runc run --d) | ||
| contains_reply "--detach" "${replies[@]}" | ||
| run ! contains_reply "--detatch" "${replies[@]}" | ||
|
|
||
| mapfile -t replies < <(complete_runc runc run --pidf) | ||
| contains_reply "--pidfd-socket" "${replies[@]}" | ||
| } | ||
|
|
||
| @test "exec completion includes pidfd socket and plain long flags" { | ||
| mapfile -t replies < <(complete_runc runc exec --pidf) | ||
| contains_reply "--pidfd-socket" "${replies[@]}" | ||
|
|
||
| mapfile -t replies < <(complete_runc runc exec --t) | ||
| contains_reply "--tty" "${replies[@]}" | ||
| run ! contains_reply "--tty," "${replies[@]}" | ||
| } | ||
|
|
||
| @test "format completions use table or json" { | ||
| mapfile -t replies < <(complete_runc runc list --format "") | ||
| contains_reply "table" "${replies[@]}" | ||
| contains_reply "json" "${replies[@]}" | ||
| run ! contains_reply "text" "${replies[@]}" | ||
|
|
||
| mapfile -t replies < <(complete_runc runc ps --format "") | ||
| contains_reply "table" "${replies[@]}" | ||
| contains_reply "json" "${replies[@]}" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.