Skip to content

Commit

Permalink
Added version option
Browse files Browse the repository at this point in the history
  • Loading branch information
predatorray committed May 21, 2020
1 parent eb60dd7 commit 5d34cf5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/output/
VERSION
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
NAME=kubectl-tmux-exec
VERSION=0.1.0
GIT_TAG := $(shell git describe --tags --abbrev=0)
GIT_COMMIT_ID := $(shell git rev-parse HEAD)
VERSION := $(GIT_TAG:v%=%)

OUTPUT_DIR=output
RELEASE_FILE_NAME=$(NAME)-$(VERSION).tar.gz
Expand All @@ -8,19 +10,22 @@ SIG_FILE_NAME=$(NAME)-$(VERSION).asc
SIG_FILE_PATH=$(OUTPUT_DIR)/$(SIG_FILE_NAME)
CHECKSUM_FILE_NAME=$(RELEASE_FILE_NAME).sha256
CHECKSUM_FILE_PATH=$(OUTPUT_DIR)/$(CHECKSUM_FILE_NAME)
VERSION_FILE_PATH=VERSION

ifeq ($(OS), Windows_NT)
OS_UNAME := Windows
else
OS_UNAME := $(shell uname -s)
endif

.PHONY: build sign checksum clean mk-output-dir test
.PHONY: build version sign checksum clean mk-output-dir test

all: test $(RELEASE_FILE_PATH) $(CHECKSUM_FILE_PATH)

build: $(RELEASE_FILE_PATH)

version: $(VERSION_FILE_PATH)

test:
bats test/

Expand All @@ -32,10 +37,13 @@ mk-output-dir:
mkdir -p $(OUTPUT_DIR)

clean:
rm -rf $(RELEASE_FILE_PATH) $(CHECKSUM_FILE_PATH) $(SIG_FILE_PATH)
rm -rf $(VERSION_FILE_PATH) $(RELEASE_FILE_PATH) $(CHECKSUM_FILE_PATH) $(SIG_FILE_PATH)

$(VERSION_FILE_PATH):
echo "$(VERSION) (commit = $(GIT_COMMIT_ID))" > $(VERSION_FILE_PATH)

$(RELEASE_FILE_PATH): mk-output-dir
tar czvf $(RELEASE_FILE_PATH) bin/ LICENSE
$(RELEASE_FILE_PATH): mk-output-dir $(VERSION_FILE_PATH)
tar czvf $(RELEASE_FILE_PATH) bin/ LICENSE $(VERSION_FILE_PATH)

$(SIG_FILE_PATH): $(RELEASE_FILE_PATH)
gpg -ab $(RELEASE_FILE_PATH)
Expand Down
27 changes: 25 additions & 2 deletions bin/kubectl-tmux_exec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@

set -euf -o pipefail

# Stack Overflow: https://stackoverflow.com/a/246128/1122665
SOURCE="${BASH_SOURCE[0]}"
while [[ -h "$SOURCE" ]]; do
PROG_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$PROG_DIR/$SOURCE"
done
PROG_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

readonly PROG_NAME='kubectl tmux-exec'

declare -ra KUBECTL_SHORT_OPTS=(
Expand Down Expand Up @@ -71,6 +80,7 @@ Examples:
${PROG_NAME} -f - /bin/bash # read from stdin
Options:
-V, --version: Print the version information
-c, --container='': Container name. If omitted, the first container in the pod will be chosen
-i, --stdin=true: Pass stdin to the container (deprecated, since it's enabled by default)
-t, --tty=true: Stdin is a TTY (deprecated, since it's enabled by default)
Expand All @@ -88,6 +98,15 @@ Use "kubectl options" for a list of global command-line options (applies to all
EOF
}

function print_version() {
local version_file="${PROG_DIR}/../VERSION"
if [[ -f "${version_file}" ]]; then
cat "${version_file}"
else
echo "unknown"
fi
}

function check_required_executables() {
for exe in "$@"; do
if ! which "${exe}" 2>&1 >/dev/null; then
Expand Down Expand Up @@ -137,8 +156,8 @@ function array_contains() {

function main() {
local opts
opts=$(ggetopt -o hitdc:l:f:"$(printf '%s:' "${KUBECTL_SHORT_OPTS[@]}")" --long \
help,stdin,tty,detach,container:,selector:,remain-on-exit,select-layout:,file:,"$(printf '%s:,' "${KUBECTL_LONG_OPTS[@]}")","$(printf '%s,' "${KUBECTL_NOARG_LONG_OPTS[@]}")" -- "$@")
opts=$(ggetopt -o hVitdc:l:f:"$(printf '%s:' "${KUBECTL_SHORT_OPTS[@]}")" --long \
help,version,stdin,tty,detach,container:,selector:,remain-on-exit,select-layout:,file:,"$(printf '%s:,' "${KUBECTL_LONG_OPTS[@]}")","$(printf '%s,' "${KUBECTL_NOARG_LONG_OPTS[@]}")" -- "$@")
eval set -- $opts

local selector
Expand All @@ -155,6 +174,10 @@ function main() {
usage
exit 0
;;
-V|--version)
print_version
exit 0
;;
-c|--container)
shift
container_name="$1"
Expand Down

0 comments on commit 5d34cf5

Please sign in to comment.