summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2019-09-20 18:44:51 -0300
committerGitHub <noreply@github.com>2019-09-20 18:44:51 -0300
commit2bc52976c2c4365661b7100b83bcdbbe7c2284c7 (patch)
tree4f21574edc1a6c158c7263d184e06e293ce58989
parent2fdb55f261caca66946a3275cb6d5ad22e176836 (diff)
Add tests (#3)
-rw-r--r--.circleci/config.yml26
-rw-r--r--Makefile10
-rw-r--r--README.md9
-rwxr-xr-xnavi2
-rwxr-xr-xscripts/install (renamed from scripts/symlink)0
-rwxr-xr-xscripts/release26
-rwxr-xr-xscripts/uninstall5
-rwxr-xr-xsrc/cheat.sh2
-rw-r--r--src/docs.sh4
-rw-r--r--test/core.sh13
-rwxr-xr-xtest/find_cheats10
11 files changed, 95 insertions, 12 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..9e55fe2
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,26 @@
+# Clojure CircleCI 2.0 configuration file
+#
+# Check https://circleci.com/docs/2.0/language-clojure/ for more details
+#
+version: 2
+
+job_defaults: &defaults
+ docker:
+ - image: frolvlad/alpine-bash
+ working_directory: ~/repo
+ environment:
+ ENVIRONMENT: "test"
+ TERM: "dumb"
+
+jobs:
+ tests:
+ <<: *defaults
+ steps:
+ - checkout
+ - run: ./test/find_cheats
+
+workflows:
+ version: 2
+ run-tests:
+ jobs:
+ - tests \ No newline at end of file
diff --git a/Makefile b/Makefile
index c22e144..8000b88 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-BIN ?= navi
-PREFIX ?= /usr/local
-
install:
- scripts/symlink
+ scripts/install
uninstall:
- rm -f $(PREFIX)/bin/$(BIN)
+ scripts/uninstall
+
+release:
+ scripts/release
diff --git a/README.md b/README.md
index 9a96c8a..4944ad5 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# navi
+# navi [![CircleCI](https://circleci.com/gh/denisidoro/navi.svg?style=svg)](https://circleci.com/gh/denisidoro/navi)
An interactive cheatsheet tool for the command-line so that you'll never say the following again:
@@ -53,7 +53,12 @@ Or you can launch and browser and search for instructions on Google, but that ta
In this case, you need to pass the directory which contains `.cheat` files as in:
```sh
-navi --dir /folder/with/cheats
+navi --dir "/folder/with/cheats"
+```
+
+Alternatively, you can set an environment variable in your `.bashrc`-like file:
+```sh
+export NAVI_DIR="/folder/with/cheats"
```
## .cheat syntax
diff --git a/navi b/navi
index 4d23013..b4183e0 100755
--- a/navi
+++ b/navi
@@ -22,6 +22,6 @@ source "${SCRIPT_DIR}/src/main.sh"
##? --print Prevent script execution [default: false]
##? --no-interpolation Prevent argument interpolation [default: false]
-VERSION="0.5.0"
+VERSION="0.6.0"
docs::eval "$@"
main "$@"
diff --git a/scripts/symlink b/scripts/install
index 2ab7ab9..2ab7ab9 100755
--- a/scripts/symlink
+++ b/scripts/install
diff --git a/scripts/release b/scripts/release
new file mode 100755
index 0000000..f854c55
--- /dev/null
+++ b/scripts/release
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+cd "$SCRIPT_DIR"
+
+tag="v$*"
+tar="https://github.com/denisidoro/navi/archive/v${tag}.tar.gz"
+formula="/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/navi.rb"
+
+echo "Attempting to release version ${tag}..."
+
+echo "git tag"
+git tag -a "$tag" -m "$tag"
+
+echo "git push"
+git push --follow-tags
+
+echo "rm formula"
+rm "$formula" || true
+
+echo "brew create"
+brew create "$tar"
+
+echo "output"
+grep "url" "$formula" -A1 \ No newline at end of file
diff --git a/scripts/uninstall b/scripts/uninstall
new file mode 100755
index 0000000..1a90c6a
--- /dev/null
+++ b/scripts/uninstall
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BIN="/usr/local/bin/navi"
+rm -rf "$BIN" || true \ No newline at end of file
diff --git a/src/cheat.sh b/src/cheat.sh
index 5e6b340..5ce0208 100755
--- a/src/cheat.sh
+++ b/src/cheat.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
cheat::find() {
- find "${cheat_dir:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat'
+ find "${NAVI_DIR:-"${SCRIPT_DIR}/cheats"}" -iname '*.cheat'
}
cheat::read_many() {
diff --git a/src/docs.sh b/src/docs.sh
index 7a125ea..ad03944 100644
--- a/src/docs.sh
+++ b/src/docs.sh
@@ -14,7 +14,7 @@ docs::eval() {
for arg in $@; do
case $wait_for in
- dir) cheat_dir="$arg"; wait_for="";;
+ dir) NAVI_DIR="$arg"; wait_for="";;
esac
case $arg in
@@ -25,6 +25,4 @@ docs::eval() {
-d|--dir) wait_for="dir";;
esac
done
-
- echo "cheat_dir: ${cheat_dir:-}"
}
diff --git a/test/core.sh b/test/core.sh
new file mode 100644
index 0000000..78d578e
--- /dev/null
+++ b/test/core.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+source <(
+grep -v 'main ' "${SCRIPT_DIR}/navi" | sed -E "s|export.*|export SCRIPT_DIR=\"${SCRIPT_DIR}\"|")
+
+test::success() {
+ echo "Test passed!"
+}
+
+test::fail() {
+ echo "Test failed..."
+ exit 42
+} \ No newline at end of file
diff --git a/test/find_cheats b/test/find_cheats
new file mode 100755
index 0000000..849d044
--- /dev/null
+++ b/test/find_cheats
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+source "${SCRIPT_DIR}/test/core.sh"
+
+cheat::find \
+ | grep -q "docker.cheat" \
+ && test::success \
+ || test::fail