Skip to content

Commit

Permalink
Merge pull request #79 from scality/make-shell-command
Browse files Browse the repository at this point in the history
Makefile: Add `C` option to `shell` target
  • Loading branch information
NicolasT committed Jun 22, 2018
2 parents d56922a + 06c5bbc commit b642f73
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
.POSIX:

# Using this variable, on can run shell commands or scripts inside a `make
# shell` environment easily.
# The following values are supported:
# - `-`, in which case `bash` will be invoked as-is, and a script could be
# passed on `stdin` (`echo "echo 123" | make shell C=-`). Unlike the
# invocation without `C` being set, the exit code will be retained.
# - A file, in which case `bash $C` will be invoked.
# - Any other string, which will be passed verbatim to `bash -c "$C"`.
C=

MAKEFLAGS += -r
.DEFAULT_GOAL := default
.DELETE_ON_ERROR:
Expand Down Expand Up @@ -119,8 +129,20 @@ $(BASHRC): $(SHELL_ENV_EXISTS) hack/shell-bashrc
$(V)sed s:@VENV_ACTIVATE@:$(VENV_ACTIVATE):g < hack/shell-bashrc > $@ || (rm -f $@; exit 1)

shell: $(VENV_EXISTS) $(REQUIREMENTS_INSTALLED) $(KUBECTL) $(HELM) $(BASHRC) ## Run a shell with `ansible-playbook`, `kubectl` and `helm` pre-installed
$(V)echo "Launching metal-k8s shell environment. Run 'exit' to quit."
$(V)bash --rcfile $(BASHRC) ||:
$(V)if test -z "$(C)"; then \
# Interactive shell \
echo "Launching metal-k8s shell environment. Run 'exit' to quit."; \
bash --rcfile $(BASHRC) ||:; \
elif test "x$(C)" = "x-"; then \
# Semi-interactive shell, keeping exit-code \
bash --rcfile $(BASHRC); \
elif test -e "$(C)"; then \
# A script \
bash --rcfile $(BASHRC) "$(C)"; \
else \
# A command \
bash --rcfile $(BASHRC) -c "$(C)"; \
fi
.PHONY: shell

clean-shell: ## Clean-up the `shell` environment
Expand Down

0 comments on commit b642f73

Please sign in to comment.