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