# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ########################### just completion _just_subcommand_options(){ local cmd=$1 for w in $(just $cmd --help) do [[ $w =~ ^-. ]] && printf "%s\n" ${w//,/" "} done } _just_targets(){ command -v python3 &>/dev/null || return python3 - </dev/null)) COMPREPLY=($(compgen -f -W "${_opts[*]} ${_targets[*]}" -- $word )) compopt -o plusdirs -o bashdefault -o default else COMPREPLY=($(compgen -W "${SUBCOMMANDS[*]}" -- $word)) fi } complete -F _just_completion just ########################### just-mr completion _just-mr_options(){ local cmd=$1 for w in $($cmd --help 2>/dev/null) do [[ $w =~ ^-. ]] && printf "%s\n" ${w//,/" "} done } _just-mr_parse_subcommand() { local readonly FLAGS=("--help\n-h\n--norc\ndo") # treat 'do' as flag local readonly OPTIONS=("--distdir\n--just\n--local-build-root\n--main\n--rc\n-C\n-L") shift while [ -n "$1" ]; do if echo -e "$FLAGS" | grep -q -- "^$1$"; then shift; continue; fi if echo -e "$OPTIONS" | grep -q -- "^$1$"; then shift; shift; continue; fi if [ "$1" = "--" ]; then shift; fi break done echo "$1" } _just-mr_repos(){ command -v python3 &>/dev/null || return local CONF=$(just-mr setup --all 2>/dev/null) if [ ! -f "$CONF" ]; then return; fi python3 - </dev/null) _just_completion else # just-mr top-level options local _opts=($(_just-mr_options "just-mr")) COMPREPLY=($(compgen -W "${_opts[*]} ${SUBCOMMANDS[*]}" -- $word)) fi } complete -F _just-mr_completion just-mr