Skip to content

Commit

Permalink
v0.1.3 - Support value list list
Browse files Browse the repository at this point in the history
  • Loading branch information
fvumbaca committed Dec 11, 2018
1 parent 399ff33 commit 248b0f6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
_gen
*.todo
5 changes: 4 additions & 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.2/ysh)"
$ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/azohra/yaml.sh/v0.1.3/ysh)"
```

## Flags
Expand All @@ -51,6 +51,9 @@ $ YSH_LIB=1;source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/a
`-l, --list <query>`
> Query for a list.
`-L, --list <query>`
> Query for a list of values. Guarentees results are all values.
`-c, --count <query>`
> Query for a list and count the elements.
Expand Down
10 changes: 9 additions & 1 deletion 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.2'
YSH_version='0.1.3'

# Will be replaced by builder with minified awk parser program
YAML_AWK_PARSER=$(cat src/ysh.awk)
Expand All @@ -25,6 +25,10 @@ YSH_list() {
YSH_sub "${1}" "${2}" | grep -E "^\\[[0-9]+\\]"
}

YSH_list_values() {
YSH_sub "${1}" "${2}" | grep -E "^\\[[0-9]+\\]=" | sed "s/^\\[[0-9]\\]=//" | sed "s/[(^\")(\"$)]//g"
}

YSH_count() {
YSH_sub "${1}" "${2}" | grep -oE "^\\[[0-9]+\\]" | uniq | wc -l
}
Expand Down Expand Up @@ -106,6 +110,10 @@ ysh() {
YSH_RAW_STRING="$(YSH_list "${YSH_RAW_STRING}" "${2}")"
shift
;;
-L|--list-val)
YSH_RAW_STRING="$(YSH_list_values "${YSH_RAW_STRING}" "${2}")"
shift
;;
-i|--index)
YSH_RAW_STRING="$(YSH_index "${YSH_RAW_STRING}" "${2}")"
shift
Expand Down
10 changes: 10 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ testSimpleList() {
assertEquals 4 $(wc -l <<< "${result}")
}

testSimpleListValues() {
result=$(ysh -T "${file}" -L simple_list.list)
assertContains "${result}" "one"
assertContains "${result}" "two"
assertContains "${result}" "three"
assertContains "${result}" "four"
assertNotContains "${result}" "\""
assertEquals 4 $(wc -l <<< "${result}")
}

testSimpleCount() {
result=$(ysh -T "$file" -c simple_list.list)
assertEquals 4 $result
Expand Down
9 changes: 8 additions & 1 deletion ysh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash
YSH_version='0.1.2'
YSH_version='0.1.3'
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 Down Expand Up @@ -35,6 +35,9 @@ YSH_sub() {
YSH_list() {
YSH_sub "${1}" "${2}" | grep -E "^\\[[0-9]+\\]"
}
YSH_list_values() {
YSH_sub "${1}" "${2}" | grep -E "^\\[[0-9]+\\]=" | sed "s/^\\[[0-9]\\]=//" | sed "s/[(^\")(\"$)]//g"
}
YSH_count() {
YSH_sub "${1}" "${2}" | grep -oE "^\\[[0-9]+\\]" | uniq | wc -l
}
Expand Down Expand Up @@ -107,6 +110,10 @@ ysh() {
YSH_RAW_STRING="$(YSH_list "${YSH_RAW_STRING}" "${2}")"
shift
;;
-L|--list-val)
YSH_RAW_STRING="$(YSH_list_values "${YSH_RAW_STRING}" "${2}")"
shift
;;
-i|--index)
YSH_RAW_STRING="$(YSH_index "${YSH_RAW_STRING}" "${2}")"
shift
Expand Down

0 comments on commit 248b0f6

Please sign in to comment.