| 1 |
# Oil user feedback |
| 2 |
|
| 3 |
# From Zulip: |
| 4 |
# |
| 5 |
# https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/Experience.20using.20oil |
| 6 |
|
| 7 |
#### setvar |
| 8 |
|
| 9 |
# This seems to work as expected? |
| 10 |
|
| 11 |
proc get_opt(arg, :out) { |
| 12 |
setvar out = arg |
| 13 |
} |
| 14 |
var a = '' |
| 15 |
get_opt a 'lol' |
| 16 |
echo hi |
| 17 |
## status: 1 |
| 18 |
## STDOUT: |
| 19 |
## END |
| 20 |
|
| 21 |
#### !== operator |
| 22 |
var a = 'bar' |
| 23 |
|
| 24 |
if (a !== 'foo') { |
| 25 |
echo 'not equal' |
| 26 |
} |
| 27 |
|
| 28 |
if (a !== 'bar') { |
| 29 |
echo 'should not get here' |
| 30 |
} |
| 31 |
|
| 32 |
# NOTE: a !== foo is idiomatic) |
| 33 |
if ("$a" !== 'bar') { |
| 34 |
echo 'should not get here' |
| 35 |
} |
| 36 |
|
| 37 |
## STDOUT: |
| 38 |
not equal |
| 39 |
## END |
| 40 |
|
| 41 |
|
| 42 |
#### elif bug |
| 43 |
if (true) { |
| 44 |
echo A |
| 45 |
} elif (true) { |
| 46 |
echo B |
| 47 |
} elif (true) { |
| 48 |
echo C |
| 49 |
} else { |
| 50 |
echo else |
| 51 |
} |
| 52 |
## STDOUT: |
| 53 |
A |
| 54 |
## END |
| 55 |
|
| 56 |
#### global vars |
| 57 |
builtin set -u |
| 58 |
|
| 59 |
main() { |
| 60 |
source $REPO_ROOT/spec/testdata/global-lib.sh |
| 61 |
} |
| 62 |
|
| 63 |
main |
| 64 |
test_func |
| 65 |
|
| 66 |
## status: 1 |
| 67 |
## STDOUT: |
| 68 |
## END |
| 69 |
|
| 70 |
#### Julia port |
| 71 |
|
| 72 |
# https://lobste.rs/s/ritbgc/what_glue_languages_do_you_use_like#c_nhikri |
| 73 |
# |
| 74 |
# See bash counterpart in spec/blog1.test.sh |
| 75 |
|
| 76 |
git-branch-merged() { |
| 77 |
cat <<EOF |
| 78 |
foo |
| 79 |
* bar |
| 80 |
baz |
| 81 |
master |
| 82 |
EOF |
| 83 |
} |
| 84 |
|
| 85 |
# With bash-style readarray. The -t is annoying. |
| 86 |
git-branch-merged | while read --line { |
| 87 |
# Note: this can't be 'const' because const is dynamic like 'readonly'. And |
| 88 |
# we don't have block scope. |
| 89 |
var line = _line.strip() # removing leading space |
| 90 |
|
| 91 |
# with glob: line ~~ '\**' (awkward) |
| 92 |
# with regex: line ~ / %start '*' / (not terrible, but somewhat complex) |
| 93 |
|
| 94 |
# Other ideas: |
| 95 |
# line `startswith` 'a' |
| 96 |
# line `endswith` 'b' |
| 97 |
|
| 98 |
# line %startswith 'a' |
| 99 |
# line %endswith 'b' |
| 100 |
|
| 101 |
if (line !== 'master' and not line.startswith('*')) { |
| 102 |
echo $line |
| 103 |
} |
| 104 |
} | readarray -t :branches |
| 105 |
|
| 106 |
if (len(branches) === 0) { |
| 107 |
echo "No merged branches" |
| 108 |
} else { |
| 109 |
write git branch -D @branches |
| 110 |
} |
| 111 |
|
| 112 |
# With "append". Hm read --lines isn't bad. |
| 113 |
var branches2 = %() |
| 114 |
git-branch-merged | while read --line { |
| 115 |
var line2 = _line.strip() # removing leading space |
| 116 |
if (line2 !== 'master' and not line2.startswith('*')) { |
| 117 |
append :branches2 $line2 |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
write -- ___ @branches2 |
| 122 |
|
| 123 |
## STDOUT: |
| 124 |
git |
| 125 |
branch |
| 126 |
-D |
| 127 |
foo |
| 128 |
baz |
| 129 |
___ |
| 130 |
foo |
| 131 |
baz |
| 132 |
## END |
| 133 |
|
| 134 |
#### readonly in loop: explains why const doesn't work |
| 135 |
|
| 136 |
# TODO: Might want to change const in Oil... |
| 137 |
# bash actually prevents assignment and prints a warning, DOH. |
| 138 |
|
| 139 |
seq 3 | while read -r line; do |
| 140 |
readonly stripped=${line//1/x} |
| 141 |
#declare stripped=${line//1/x} |
| 142 |
echo $stripped |
| 143 |
done |
| 144 |
## status: 1 |
| 145 |
## STDOUT: |
| 146 |
x |
| 147 |
## END |
| 148 |
|
| 149 |
|
| 150 |
#### Eggex bug in a loop |
| 151 |
|
| 152 |
# https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/A.20list.20of.20feedback |
| 153 |
for i in @(seq 2) { |
| 154 |
# BUG: This crashes here, but NOT when extracted! Bad. |
| 155 |
var pat = / 'test' word+ / |
| 156 |
if ("test$i" ~ pat) { |
| 157 |
echo yes |
| 158 |
} |
| 159 |
} |
| 160 |
## STDOUT: |
| 161 |
yes |
| 162 |
yes |
| 163 |
## END |
| 164 |
|
| 165 |
|
| 166 |
#### Append object onto Array |
| 167 |
var e = [] |
| 168 |
|
| 169 |
# %() is also acceptable, but we prefer Python-like [] for objects. |
| 170 |
# %() is more for an array of strings |
| 171 |
# var e = %() |
| 172 |
|
| 173 |
for i in @(seq 2) { |
| 174 |
var o = {} |
| 175 |
setvar o[i] = "Test $i" |
| 176 |
|
| 177 |
# push builtin is only for strings |
| 178 |
|
| 179 |
# The _ keyword puts you in EXPRESSION MODE. Then use Python-like methods. |
| 180 |
# Is this awkward? We could also do setvar e[] = o to append? What about |
| 181 |
# extend? |
| 182 |
|
| 183 |
#_ e.append(o) |
| 184 |
_ append(e, o) |
| 185 |
} |
| 186 |
|
| 187 |
json write (e) |
| 188 |
|
| 189 |
## STDOUT: |
| 190 |
[ |
| 191 |
{ |
| 192 |
"1": "Test 1" |
| 193 |
}, |
| 194 |
{ |
| 195 |
"2": "Test 2" |
| 196 |
} |
| 197 |
] |
| 198 |
## END |
| 199 |
|
| 200 |
#### Invalid op on string |
| 201 |
shopt -s oil:all |
| 202 |
|
| 203 |
var clients = {'email': 'foo'} |
| 204 |
for c in @clients { |
| 205 |
echo $c |
| 206 |
# A user tickled this. I think this should make the whole 'const' line fail |
| 207 |
# with code 1 or 2? |
| 208 |
const e = c->email |
| 209 |
} |
| 210 |
## status: 3 |
| 211 |
## STDOUT: |
| 212 |
email |
| 213 |
## END |