Skip to content

Commit

Permalink
feat(completions): add Bash and fish
Browse files Browse the repository at this point in the history
These completions only apply to the command `remarshal`,
not `foo2bar` short commands.
  • Loading branch information
dbohdan committed Dec 26, 2024
1 parent 662d11d commit 5d37ce1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions completions/install.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env fish

cd "$(path dirname "$(status filename)")"

set --local src remarshal.fish
set --local dst $__fish_config_dir/completions/

printf 'copying "%s" to "%s"\n' $src $dst

cp $src $dst
41 changes: 41 additions & 0 deletions completions/remarshal.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
_remarshal() {
local cur prev opts formats input_formats output_formats

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD - 1]}

formats='cbor json msgpack toml yaml'
input_formats=$formats
output_formats="$formats python"

opts='--help --version --from --if --input-format --input --indent --stringify --max-values --output --sort-keys --to --of --output-format --unwrap --verbose --width --wrap --yaml-style'

case "${prev}" in
--from | --if | --input-format | -f)
COMPREPLY=($(compgen -W "${input_formats}" -- ${cur}))
return 0
;;
--to | --of | --output-format | -t)
COMPREPLY=($(compgen -W "${output_formats}" -- ${cur}))
return 0
;;
--yaml-style)
COMPREPLY=($(compgen -W '\" '"\\' '|' '>'" -- ${cur}))
return 0
;;
--input | -i | --output | -o)
COMPREPLY=($(compgen -f -- ${cur}))
return 0
;;
*)
if [[ ${cur} == -* ]]; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
else
COMPREPLY=($(compgen -f -- ${cur}))
fi
;;
esac
}

complete -F _remarshal remarshal
20 changes: 20 additions & 0 deletions completions/remarshal.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
complete -c remarshal -s h -l help -d "Show help message and exit"
complete -c remarshal -s v -l version -d "Show program's version number and exit"

complete -c remarshal -s f -l from -l if -l input-format -x -a "cbor json msgpack toml yaml" -d "Input format"

complete -c remarshal -s i -l input -r -d "Input file"
complete -c remarshal -s o -l output -r -d "Output file"

complete -c remarshal -s t -l to -l of -l output-format -x -a "cbor json msgpack python toml yaml" -d "Output format"

complete -c remarshal -l indent -x -d "JSON and YAML indentation"
complete -c remarshal -s k -l stringify -d "Turn special values into strings"
complete -c remarshal -l max-values -x -d "Maximum number of values in input data"
complete -c remarshal -s s -l sort-keys -d "Sort JSON, Python, and TOML keys"
complete -c remarshal -l width -x -d "Python and YAML line width"
complete -c remarshal -l yaml-style -x -a '"\'" "\\"" "|" ">"' -d "YAML formatting style"

complete -c remarshal -l unwrap -x -d "Only output data under given key"
complete -c remarshal -l verbose -d "Print debug information on error"
complete -c remarshal -l wrap -x -d "Wrap data in a map with given key"

0 comments on commit 5d37ce1

Please sign in to comment.