@axway/axway-central-cli
Version:
Manage APIs, services and publish to the Amplify Marketplace
100 lines (97 loc) • 2.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.completion = void 0;
var _cli = require("../../cli");
const coreCliCmd = 'axway';
const completionZsh = `###-begin-amplify-central-completions-###
_amplify_central_completions()
{
local state
_arguments -C \\
{-f,--file=}':: :_files' \\
'1: :(engage)' \\
'*: :->cmd'
case $state in
cmd)
local reply
local si=$IFS
IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" ${coreCliCmd} central completion --get-completions "\${words[@]}"))
IFS=$si
_describe 'values' reply
;;
esac
}
compdef _amplify_central_completions amplify
###-end-amplify-central-completions-###
`;
const completionBash = `###-begin-amplify-central-completions-###
_amplify_central_completions()
{
local cur="\${COMP_WORDS[COMP_CWORD]}"
local prev="\${COMP_WORDS[COMP_CWORD-1]}"
local twoPrev="\${COMP_WORDS[COMP_CWORD-2]}"
local options=$(${coreCliCmd} engage completion --get-completions "\${COMP_WORDS[@]}")
case $COMP_CWORD in
1) COMPREPLY=("engage");;
2) COMPREPLY=($(compgen -W "$options" -- "$cur"));;
3) compopt +o default; COMPREPLY=();; # disable file completion
*)
if [ "$prev" == "-f" ] || \\
# the COMP_WORDBREAKS var includes '=' so --file= is handled as two words and comes out as '--file' '='
([ "$cur" == "=" ] && [ "$prev" == "--file" ]) || \\
([ "$prev" == "=" ] && [ "$twoPrev" == "--file" ]);
then
# add file completion
COMPREPLY=()
else
# disable file completion
compopt +o default; COMPREPLY=()
fi
;;
esac
}
complete -o default -F _amplify_central_completions amplify
###-end-amplify-central-completions-###
`;
const action = ({
argv,
console
}) => {
const {
args,
getCompletions,
zsh,
bash
} = argv;
if (getCompletions) {
if (args[0] === coreCliCmd && args[1] === 'engage' && args.length <= 3) {
/** get core commands from CLI-kit params */
Object.keys(_cli.cliParams.commands).forEach(cmd => console.log(cmd));
}
} else if (zsh) {
console.log(completionZsh);
} else if (bash) {
console.log(completionBash);
}
};
const completion = exports.completion = {
action,
args: ['args...'],
desc: 'Output shell completion code',
options: {
'--get-completions': {
type: 'bool',
hidden: true // used only by autocompletion script itself
},
'--zsh': {
type: 'bool',
desc: 'Autocompletion script for zsh.'
},
'--bash': {
type: 'bool',
desc: 'Autocompletion script for bash.'
}
}
};