Allow forcing shell prompt option

Some commands are designed to leave you in a shell prompt once
executed, but it is hard to identify all such commands in the
context of remote CLI.

In order to allow users to use such commands, they can force
the shell option or force disable the shell options using the
FORCE_SHELL and FORCE_NO_SHELL variables before the command.

The README has been updated with examples on the use of
these variables

Change-Id: Ica4e155fa21067448b99c4309f4736d39f0a419d
Closes-bug: 1849505
Signed-off-by: Stefan Dinescu <stefan.dinescu@windriver.com>
This commit is contained in:
Stefan Dinescu 2019-10-24 13:19:16 +03:00
parent 328dc75cf2
commit 63d1a87a6c
2 changed files with 35 additions and 4 deletions

View File

@ -137,3 +137,15 @@ kubectl config --kubeconfig ${OUTPUT_FILE} use-context stxcluster-default
2. openstack image create --disk-format qcow2 --container-format bare \
--public --file /wd/centos63.qcow2 centos63-image
7. Some commands used by remote CLI are designed to leave you in a shell prompt.
Examples of such commands are "openstack" or "kubectl exec -ti <pod_name>
-- /bin/bash". There are cases where the mechanism for identifying commands
that should leave you in a shell prompt is not identifying them correctly.
If users encounter such scenarios, they can force the shell or force disable
the shell options using the FORCE_SHELL or FORCE_NO_SHELL variables before
the command. You cannot use both variables at the same time.
Examples:
- force shell: FORCE_SHELL=true kubectl exec -ti <pod_name> -- /bin/bash
- disable shell: FORCE_NO_SHELL=true kubectl exec <pod_name> -- ls

View File

@ -35,8 +35,27 @@ for exp in $EXPORTS; do
fi
done
if [ -z "$2" ]; then
exec docker run -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
else
exec docker run -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
if [[ -z "$FORCE_SHELL" ]] || [[ "$FORCE_SHELL" != "true" ]]; then
FORCE_SHELL="false"
fi
if [[ -z "$FORCE_NO_SHELL" ]] || [[ "$FORCE_NO_SHELL" != "true" ]]; then
FORCE_NO_SHELL="false"
fi
if [[ "$FORCE_SHELL" == "true" ]] && [[ "$FORCE_NO_SHELL" == "true" ]]; then
echo "Error: cannot set both FORCE_SHELLL and FORCE_NO_SHELL variables at the same time".
echo "Unset one of them and re-run the command"
exit 1
fi
if [[ "$FORCE_SHELL" == "true" ]]; then
exec docker run --rm -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
elif [[ "$FORCE_NO_SHELL" == "true" ]]; then
exec docker run --rm -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
elif [ -z "$2" ]; then
exec docker run --rm -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
else
exec docker run --rm -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@"
fi