Skip to content

Commit

Permalink
v0.1.4 - Now supports stdin as default input method
Browse files Browse the repository at this point in the history
  • Loading branch information
fvumbaca committed Dec 12, 2018
1 parent 248b0f6 commit 5f9367f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 42 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
BUILDERS=$(shell find build/*)
.PHONY: lint test all install
BUILDERS = $(shell find build/*)

.PHONY: lint test all install uninstall docs

all: ysh lint test

ysh: src/ysh.sh src/ysh.awk Makefile $(BUILDERS)
Expand All @@ -23,3 +25,11 @@ install: ysh
uninstall:
@echo "🗑️ Uninstalling ysh"
@rm /usr/local/bin/ysh

docs: ysh
@echo "📚 Updating docs"
$(eval VERSION := $(shell grep "YSH_version=" ysh | sed "s/YSH_version='//" | sed "s/'$$//"))
@awk -v version=$(VERSION) -f build/docbuilder.awk README.md > .tmp_README.md
@mv .tmp_README.md README.md
@awk -v version=$(VERSION) -f build/docbuilder.awk _static/_get/index.html > .tmp_index.html
@mv .tmp_index.html _static/_get/index.html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ YSH_LIB=1;source /usr/local/bin/ysh

If you want the internet as your only dependency:
```bash
$ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.3/ysh)"
$ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.4/ysh)"
```

## Flags
Expand Down
4 changes: 2 additions & 2 deletions _static/_get/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.2/ysh --output /usr/local/bin/ysh
chmod u+x /usr/local/bin/ysh
curl -s -L https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.4/ysh --output /usr/local/bin/ysh;
chmod u+x /usr/local/bin/ysh
8 changes: 8 additions & 0 deletions build/docbuilder.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/awk

/https:\/\/raw.githubusercontent.com\/azohra\/yaml.sh\/v[0-9]+.[0-9]+.[0-9]+\/ysh/ {
sub(/https:\/\/raw.githubusercontent.com\/azohra\/yaml.sh\/v[0-9]+.[0-9]+.[0-9]+\/ysh/, "https://raw.githubusercontent.com/azohra/yaml.sh/v" version "/ysh")
print
next
}
{print}
48 changes: 29 additions & 19 deletions src/ysh.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/bash
# shellcheck source=/dev/null
YSH_version='0.1.3'
YSH_version='0.1.4'

# Will be replaced by builder with minified awk parser program
YAML_AWK_PARSER=$(cat src/ysh.awk)
Expand All @@ -9,6 +9,10 @@ YSH_parse() {
awk "${YAML_AWK_PARSER}" "${1}"
}

YSH_parse_sdin() {
awk "${YAML_AWK_PARSER}"
}

YSH_query() {
grep -E "^${2}" <<< "${1}" | sed -E "s/^${2}[\\.=]?//"
}
Expand Down Expand Up @@ -56,11 +60,13 @@ YSH_next_block() {

YSH_usage() {
echo ""
echo "Usage: ysh [flags]"
echo "Usage: ysh [-fT input] [queries]"
echo ""
echo "flags:"
echo "input:"
echo " -f, --file <file_name> parse file"
echo " -T, --transpiled <file_name> use pre-transpiled file"
echo ""
echo "queries:"
echo " -q, --query <query> generic query"
echo " -Q, --query-val <query> safe query. Guarentees a value."
echo " -s, --sub <query> sub structure. No values."
Expand All @@ -77,23 +83,27 @@ YSH_usage() {

ysh() {
local YSH_RAW_STRING=""
case "$1" in
-v|--version)
echo "v${YSH_version}" && exit 0
;;
-h|--help)
YSH_usage
;;
-f|--file)
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift; shift
;;
-T|--transpiled)
YSH_RAW_STRING="${2}"
shift; shift
;;
*)
YSH_RAW_STRING="$(YSH_parse_sdin)"
;;
esac
while [ $# -gt 0 ] ; do

case "$1" in
-v|--version)
echo "v${YSH_version}" && exit 0
;;
-h|--help)
YSH_usage
;;
-f|--file)
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift
;;
-T|--transpiled)
YSH_RAW_STRING="${2}"
shift
;;
-q|--query)
YSH_RAW_STRING="$(YSH_query "${YSH_RAW_STRING}" "${2}")"
shift
Expand Down Expand Up @@ -142,8 +152,8 @@ ysh() {
;;
esac
shift
if [[ $# -eq 0 ]]; then echo "${YSH_RAW_STRING}"; fi
done
if [[ $# -eq 0 ]]; then echo "${YSH_RAW_STRING}"; fi
}
if [[ YSH_LIB -ne 1 ]]; then
if [[ $# -eq 0 ]] ; then YSH_usage; exit 1; fi
Expand Down
46 changes: 28 additions & 18 deletions ysh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
YSH_version='0.1.3'
YSH_version='0.1.4'
YAML_AWK_PARSER='
function raise(msg) { print msg > "/dev/stderr"; if (force_complete) { exit_status = 1; } else { exit 1; };};
function level() { match($0, /^[[:space:]]*/); if (RLENGTH % 2 != 0) { raise("Bad indentation on line "NR". Number of spaces uneven."); }; return RLENGTH / 2;};
Expand All @@ -23,6 +23,9 @@ function check_started() { if (started == 0) { raise("Keys must be added before
YSH_parse() {
awk "${YAML_AWK_PARSER}" "${1}"
}
YSH_parse_sdin() {
awk "${YAML_AWK_PARSER}"
}
YSH_query() {
grep -E "^${2}" <<< "${1}" | sed -E "s/^${2}[\\.=]?//"
}
Expand Down Expand Up @@ -58,11 +61,13 @@ YSH_next_block() {
}
YSH_usage() {
echo ""
echo "Usage: ysh [flags]"
echo "Usage: ysh [-fT input] [queries]"
echo ""
echo "flags:"
echo "input:"
echo " -f, --file <file_name> parse file"
echo " -T, --transpiled <file_name> use pre-transpiled file"
echo ""
echo "queries:"
echo " -q, --query <query> generic query"
echo " -Q, --query-val <query> safe query. Guarentees a value."
echo " -s, --sub <query> sub structure. No values."
Expand All @@ -78,22 +83,27 @@ YSH_usage() {
}
ysh() {
local YSH_RAW_STRING=""
case "$1" in
-v|--version)
echo "v${YSH_version}" && exit 0
;;
-h|--help)
YSH_usage
;;
-f|--file)
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift; shift
;;
-T|--transpiled)
YSH_RAW_STRING="${2}"
shift; shift
;;
*)
YSH_RAW_STRING="$(YSH_parse_sdin)"
;;
esac
while [ $# -gt 0 ] ; do
case "$1" in
-v|--version)
echo "v${YSH_version}" && exit 0
;;
-h|--help)
YSH_usage
;;
-f|--file)
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift
;;
-T|--transpiled)
YSH_RAW_STRING="${2}"
shift
;;
-q|--query)
YSH_RAW_STRING="$(YSH_query "${YSH_RAW_STRING}" "${2}")"
shift
Expand Down Expand Up @@ -142,8 +152,8 @@ ysh() {
;;
esac
shift
if [[ $# -eq 0 ]]; then echo "${YSH_RAW_STRING}"; fi
done
if [[ $# -eq 0 ]]; then echo "${YSH_RAW_STRING}"; fi
}
if [[ YSH_LIB -ne 1 ]]; then
if [[ $# -eq 0 ]] ; then YSH_usage; exit 1; fi
Expand Down

0 comments on commit 5f9367f

Please sign in to comment.