yoursweater :
Basically, I'm trying to disable a CLI's "delete" function in order to prevent myself (and others) from inadvertently deleting our environments. I want to basically intercept amplify delete
(including subsequent arguments) and echo something like you are not supposed to do this.
amplify() {
local -a args=( )
for arg; do
# if arg == delete
echo "This command is disabled."
done
}
The catch is that I still want the rest of the CLI arguments to work. So if I type in amplify status
, that should run. Just not amplify delete
or amplify delete --arg2 --arg3 --etc
Inian :
You can write a wrapper over the amplify()
function like you had and check if the argument is set to delete
amplify() {
[ "$1" = "delete" ] && { >&2 printf '%s\n' "This command is disabled."; return; }
command amplify "$@"
}
The command
before amplify
ensures this time, the binary is searched int the PATH
variable for execution.