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