Skip to content

Commit

Permalink
Add build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Apr 22, 2021
1 parent c3eed9e commit 880fbbc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/.shellspec-quick.log
/report/
/coverage/
/bin

5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:edge
RUN apk add --no-cache shellcheck bash make
WORKDIR /root
COPY ./ ./
CMD [ "bash" ]
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
PREFIX ?= /usr/local
BINDIR := $(PREFIX)/bin
SHELL=bash

test:
shellspec
.PHONY: build check test testall coverage install uninstall

build: bin/getoptions bin/getoptions-generate

check:
shellcheck src/* lib/*.sh spec/*.sh examples/*.sh

test:
shellspec

testall:
shellspec -s sh
shellspec -s bash
Expand All @@ -19,3 +25,10 @@ testall:
coverage:
shellspec -s bash --kcov --kcov-options "--coveralls-id=$(COVERALLS_REPO_TOKEN)"
bash <(curl -s https://codecov.io/bash) -s coverage

bin/getoptions: src/build.sh src/getoptions lib/*.sh
src/build.sh < src/getoptions > bin/getoptions
chmod +x bin/getoptions

bin/getoptions-generate: src/getoptions-generate
cp src/getoptions-generate bin/getoptions-generate
Empty file added bin/.keep
Empty file.
15 changes: 15 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# shellcheck disable=SC2016

set -eu

while IFS= read -r line; do
case $line in
*"# @INCLUDE-FILE")
printf '\tputlines \\\n'
eval "$line" | sed "s/'/'\\\\''/g; s/^/\t\t'/; s/$/' \\\\/"
echo
;;
*) printf '%s\n' "$line" ;;
esac
done
18 changes: 12 additions & 6 deletions src/getoptions
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/bin/sh
# shellcheck disable=SC2016
# shellcheck disable=SC2016,SC2039

set -eu

VERSION="v2.5.1"
URL="https://github.com/ko1nksm/getoptions"
LICENSE="Creative Commons Zero v1.0 Universal"

if [ "${KSH_VERSION:-}" ] || [ "${ZSH_VERSION:-}" ]; then
putlines() { IFS=$'\n'$IFS; print -r -- "$*"; IFS=${IFS#?}; }
else
putlines() { printf '%s\n' "$@"; }
fi

outlibs() {
cat lib/getoptions_base.sh
cat lib/getoptions_abbr.sh
cat lib/getoptions_help.sh
cat lib/getoptions_base.sh # @INCLUDE-FILE
cat lib/getoptions_abbr.sh # @INCLUDE-FILE
cat lib/getoptions_help.sh # @INCLUDE-FILE
}

quote() {
Expand All @@ -20,11 +26,11 @@ quote() {
eval "$1=\${q:-\"''\"}"
}

case ${1:---} in (-?*)
case ${1:-} in (-?* | '')
echo "getoptions $VERSION ($URL)"
echo "License: $LICENSE"
echo 'Usage: eval "$(getoptions <parser_definition> <parser_name> [arguments...])"'
exit 1
exit ${1:+1}
esac

outlibs
Expand Down
1 change: 1 addition & 0 deletions src/getoptions-cli → src/getoptions-generate
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ elif which getoptions >/dev/null 2>&1; then
else
abort "getoptions not found"
fi
getoptions() { "$GETOPTIONS" "$@"; }

eval "$(getoptions parser_definition parse "$0")"
parse "$@"
Expand Down

0 comments on commit 880fbbc

Please sign in to comment.