OILS / _gen / bin / text_files.cc View on Github | oilshell.org

1876 lines, 159 significant
1
2#include "cpp/embedded_file.h"
3
4namespace embedded_file {
5GLOBAL_STR(gStr0, R"zZXx(
6 Errors
7 <a class="group-link" href="chap-errors.html">errors</a>
8
9
10 [UTF8] err-utf8-encode err-utf8-decode
11 [J8 String] err-j8-str-encode err-j8-str-decode
12 [J8 Lines] err-j8-lines-encode err-j8-lines-decode
13 [JSON] err-json-encode err-json-decode
14 [JSON8] err-json8-encode err-json8-decode
15)zZXx");
16
17GLOBAL_STR(gStr1, R"zZXx(
18
19 Front End <a class="group-link" href="chap-front-end.html">front-end</a>
20
21
22 [Lexing] ascii-whitespace [ \t\r\n]
23 ascii-control-chars
24)zZXx");
25
26GLOBAL_STR(gStr2, R"zZXx(
27 J8 Notation
28 <a class="group-link" href="chap-j8.html">j8</a>
29
30
31 [J8 Strings] json-string "hi"
32 json-escape \" \\ \u1234
33 surrogate-pair \ud83e\udd26
34 j8-escape \' \u{1f926} \yff
35 u-prefix u'hi'
36 b-prefix b'hi'
37 no-prefix 'hi'
38 [J8 Lines] unquoted-line
39 [JSON8] json8-num json8-str
40 X json8-list X json8-dict
41 json8-comment
42 [TSV8] column-attrs column-types
43)zZXx");
44
45GLOBAL_STR(gStr3, R"zZXx(Usage: help TOPIC?
46
47Examples:
48
49 help # this help
50 help echo # help on the 'echo' builtin
51 help command-sub # help on command sub $(date)
52
53 help oils-usage # identical to oils-for-unix --help
54 help osh-usage # osh --help
55 help ysh-usage # ysh --help
56)zZXx");
57
58GLOBAL_STR(gStr4, R"zZXx(bin/oils-for-unix is an executable that contains OSH, YSH, and more.
59
60Usage: oils-for-unix MAIN_NAME ARG*
61 MAIN_NAME ARG*
62
63It behaves like busybox. The command name can be passed as the first argument:
64
65 oils-for-unix ysh -c 'echo hi'
66
67More commonly, it's invoked through a symlink like 'ysh', which causes it to
68behave like that command:
69
70 ysh -c 'echo hi'
71)zZXx");
72
73GLOBAL_STR(gStr5, R"zZXx(
74 Builtin Commands <a class="group-link" href="chap-builtin-cmd.html">builtin-cmd</a>
75
76
77 [I/O] read echo printf
78 readarray mapfile
79 [Run Code] source . eval trap
80 [Set Options] set shopt
81 [Working Dir] cd pwd pushd popd dirs
82 [Completion] complete compgen compopt compadjust compexport
83 [Shell Process] exec X logout
84 umask ulimit times
85 [Child Process] jobs wait
86 fg X bg X kill X disown
87 [External] test [ getopts
88 [Introspection] help hash cmd/type X caller
89 [Word Lookup] command builtin
90 [Interactive] alias unalias history X fc X bind
91X [Unsupported] enable
92)zZXx");
93
94GLOBAL_STR(gStr6, R"zZXx(The reference is divided in to "chapters", each of which has its own table of
95contents. Type:
96
97 help osh-$CHAPTER
98
99Where $CHAPTER is one of:
100
101 front-end
102 command-lang
103 osh-assign
104 word-lang
105 mini-lang
106 builtin-cmd
107 option
108 special-var
109 plugin
110
111Example:
112
113 help osh-word-lang
114)zZXx");
115
116GLOBAL_STR(gStr7, R"zZXx(
117 Command Language <a class="group-link" href="chap-cmd-lang.html">cmd-lang</a>
118
119
120 [Commands] simple-command semicolon ;
121 [Conditional] case if dbracket [[
122 true false colon :
123 bang ! and && or ||
124 [Iteration] while until for for-expr-sh ((
125 [Control Flow] break continue return exit
126 [Grouping] sh-func sh-block { subshell (
127 [Concurrency] pipe | X pipe-amp |& ampersand &
128 [Redirects] redir-file > >> >| < <> not impl: &>
129 redir-desc >& <&
130 here-doc << <<- <<<
131 [Other Command] dparen (( time X coproc X select
132)zZXx");
133
134GLOBAL_STR(gStr8, R"zZXx(
135 Front End <a class="group-link" href="chap-front-end.html">front-end</a>
136
137
138 [Usage] oils-usage osh-usage config
139 startup line-editing exit-codes
140 [Lexing] comment # line-continuation \ ascii-whitespace [ \t\r\n]
141)zZXx");
142
143GLOBAL_STR(gStr9, R"zZXx(
144 Other Mini Languages <a class="group-link" href="chap-mini-lang.html">mini-lang</a>
145
146
147 [Arithmetic] arith-context Where legacy arithmetic is allowed
148 sh-numbers 0xFF 0755 etc.
149 sh-arith 1 + 2*3 a *= 2
150 sh-logical !a && b
151 sh-bitwise ~a ^ b
152 [Boolean] bool-expr [[ ! $x && $y || $z ]]
153 test ! $x -a $y -o $z
154 bool-infix $a -nt $b $x == $y
155 bool-path -d /etc
156 bool-str -n foo -z ''
157 bool-other -o errexit -v name[index]
158 [Patterns] glob-pat *.py
159 extglob ,(*.py|*.sh)
160 regex [[ foo =~ [a-z]+ ]]
161 [Other Sublang] braces {alice,bob}@example.com
162 histsub !$ !! !n
163 char-escapes \t \c \x00 \u03bc
164)zZXx");
165
166GLOBAL_STR(gStr10, R"zZXx(
167 Global Shell Options <a class="group-link" href="chap-option.html">option</a>
168
169
170 [Errors] nounset -u errexit -e inherit_errexit pipefail
171 [Globbing] noglob -f nullglob failglob X dotglob
172 dashglob (true)
173 [Other Option] noclobber -C errtrace -E
174 [Debugging] xtrace X verbose X extdebug
175 [Interactive] emacs vi
176 [Compat] eval_unsafe_arith ignore_flags_not_impl
177)zZXx");
178
179GLOBAL_STR(gStr11, R"zZXx(
180 Assignments and Expressions <a class="group-link" href="chap-osh-assign.html">osh-assign</a>
181
182
183 [Literals] sh-array array=(a b c) array[1]=B "${a[@]}"
184 sh-assoc assoc=(['a']=1 ['b']=2) assoc['x']=b
185 [Operators] sh-assign str='xyz'
186 sh-append str+='abc'
187 [Builtins] local readonly export unset shift
188 declare typeset X let
189)zZXx");
190
191GLOBAL_STR(gStr12, R"zZXx(
192 Plugins and Hooks <a class="group-link" href="chap-plugin.html">plugin</a>
193
194
195 [Signals] SIGTERM SIGINT SIGQUIT
196 SIGTTIN SIGTTOU SIGWINCH
197 [Traps] DEBUG ERR EXIT X RETURN
198 [Words] PS1 X PS2 X PS3 PS4
199 [Completion] complete
200 [Other Plugin] PROMPT_COMMAND X command_not_found
201)zZXx");
202
203GLOBAL_STR(gStr13, R"zZXx(
204 Special Variables <a class="group-link" href="chap-special-var.html">special-var</a>
205
206
207 [POSIX Special] $@ $* $# $? $- $$ $! $0 $9
208 [Shell Vars] IFS X LANG X GLOBIGNORE
209 [Shell Options] SHELLOPTS X BASHOPTS
210 [Other Env] HOME PATH
211 [Other Special] BASH_REMATCH @PIPESTATUS
212 [Platform] HOSTNAME OSTYPE
213 [Call Stack] @BASH_SOURCE @FUNCNAME @BASH_LINENO
214 X @BASH_ARGV X @BASH_ARGC
215 [Tracing] LINENO
216 [Process State] UID EUID PPID X BASHPID
217X [Process Stack] BASH_SUBSHELL SHLVL
218X [Shell State] BASH_CMDS @DIRSTACK
219 [Completion] @COMP_WORDS COMP_CWORD COMP_LINE COMP_POINT
220 COMP_WORDBREAKS @COMPREPLY X COMP_KEY
221 X COMP_TYPE COMP_ARGV
222 [History] HISTFILE
223 [cd] PWD OLDPWD X CDPATH
224 [getopts] OPTIND OPTARG X OPTERR
225 [read] REPLY
226 [Functions] X RANDOM SECONDS
227 [Oils VM] OILS_VERSION LIB_OSH
228)zZXx");
229
230GLOBAL_STR(gStr14, R"zZXx(
231 Standard Library <a class="group-link" href="chap-stdlib.html">stdlib</a>
232
233
234 [two] log die
235 [no-quotes] nq-assert nq-run
236 nq-capture nq-capture-2
237 nq-redir nq-redir-2
238 [bash-strict]
239 [task-five]
240)zZXx");
241
242GLOBAL_STR(gStr15, R"zZXx(
243 OSH Types <a class="group-link" href="chap-type-method.html">type-method</a>
244
245
246 [OSH] BashArray BashAssoc
247)zZXx");
248
249GLOBAL_STR(gStr16, R"zZXx(bin/osh is compatible with POSIX shell, bash, and other shells.
250
251Usage: osh FLAG* SCRIPT ARG*
252 osh FLAG* -c COMMAND ARG*
253 osh FLAG*
254
255The command line accepted by `bin/osh` is compatible with /bin/sh and bash.
256
257 osh -c 'echo hi'
258 osh myscript.sh
259 echo 'echo hi' | osh
260
261It also has a few enhancements:
262
263 osh -n -c 'hello' # pretty-print the AST
264 osh --ast-format text -n -c 'hello' # print it full
265
266osh accepts POSIX sh flags, with these additions:
267
268 -n parse the program but don't execute it. Print the AST.
269 --ast-format what format the AST should be in
270)zZXx");
271
272GLOBAL_STR(gStr17, R"zZXx(
273 Word Language <a class="group-link" href="chap-word-lang.html">word-lang</a>
274
275
276 [Quotes] osh-string 'abc' $'line\n' "$var"
277 [Substitutions] command-sub $(command) `command`
278 var-sub ${var} $0 $9
279 arith-sub $((1 + 2))
280 tilde-sub ~/src
281 proc-sub diff <(sort L.txt) <(sort R.txt)
282 [Var Ops] op-test ${x:-default}
283 op-strip ${x%%suffix} etc.
284 op-patsub ${x//y/z}
285 op-index ${a[i+1}
286 op-slice ${a[@]:0:1}
287 op-format ${x@P}
288)zZXx");
289
290GLOBAL_STR(gStr18, R"zZXx(
291 Builtin Commands <a class="group-link" href="chap-builtin-cmd.html">builtin-cmd</a>
292
293
294 [Memory] cmd/append Add elements to end of array
295 pp value proc test_
296 asdl_ cell_ X gc-stats_
297 [Handle Errors] error error 'failed' (status=2)
298 try Run with errexit, set _error
299 failed Test if _error.code !== 0
300 boolstatus Enforce 0 or 1 exit status
301 assert assert [42 === f(x)]
302 [Shell State] ysh-cd ysh-shopt compatible, and takes a block
303 shvar Temporary modify global settings
304 ctx Share and update a temporary "context"
305 push-registers Save registers like $?, PIPESTATUS
306 [Modules] runproc Run a proc; use as main entry point
307 source-guard guard against duplicate 'source'
308 is-main false when sourcing a file
309 X use use names,
310 [I/O] ysh-read flags --all, -0
311 ysh-echo no -e -n with simple_echo
312 write Like echo, with --, --sep, --end
313 fork forkwait Replace & and (), and takes a block
314 fopen Open multiple streams, takes a block
315 [Hay Config] hay haynode For DSLs and config files
316 [Completion] compadjust compexport
317 [Data Formats] json read write
318 json8 read write
319)zZXx");
320
321GLOBAL_STR(gStr19, R"zZXx(
322 Builtin Functions <a class="group-link" href="chap-builtin-func.html">builtin-func</a>
323
324
325 [Values] len() func/type()
326 [Conversions] bool() int() float()
327 str() list() dict()
328 X runes() X encodeRunes()
329 X bytes() X encodeBytes()
330 [Str] X strcmp() X split() shSplit()
331 [List] join()
332 [Float] floatsEqual() X isinf() X isnan()
333 [Word] glob() maybe()
334 [Serialize] toJson() fromJson()
335 toJson8() fromJson8()
336X [J8 Decode] J8.Bool() J8.Int() ...
337 [Pattern] _group() _start() _end()
338 [Introspection] shvarGet() getVar() evalExpr()
339 [Hay Config] parseHay() evalHay()
340X [Hashing] sha1dc() sha256()
341)zZXx");
342
343GLOBAL_STR(gStr20, R"zZXx(The reference is divided in to "chapters", each of which has its own table of
344contents. Type:
345
346 help ysh-$CHAPTER
347
348Where $CHAPTER is one of:
349
350 front-end
351 command-lang
352 expr-lang
353 word-lang
354 builtin-cmd
355 option
356 special-var
357 type-method
358 builtin-func
359
360Example:
361
362 help ysh-expr-lang
363)zZXx");
364
365GLOBAL_STR(gStr21, R"zZXx(
366 Command Language <a class="group-link" href="chap-cmd-lang.html">cmd-lang</a>
367
368
369 [YSH Simple] typed-arg json write (x)
370 lazy-expr-arg assert [42 === x]
371 block-arg cd /tmp { echo $PWD }; cd /tmp (; ; blockexpr)
372 [YSH Cond] ysh-case case (x) { *.py { echo 'python' } }
373 ysh-if if (x > 0) { echo }
374 [YSH Iter] ysh-for for i, item in (mylist) { echo }
375 ysh-while while (x > 0) { echo }
376)zZXx");
377
378GLOBAL_STR(gStr22, R"zZXx(
379 Expression Language and Assignments <a class="group-link" href="chap-expr-lang.html">expr-lang</a>
380
381
382 [Assignment] assign =
383 aug-assign += -= *= /= **= //= %=
384 &= |= ^= <<= >>=
385 [Literals] atom-literal true false null
386 int-literal 42 65_536 0xFF 0o755 0b10
387 float-lit 3.14 1.5e-10
388 char-literal \\ \t \" \y00 \u{3bc}
389 X num-suffix 42 K Ki M Mi G Gi T Ti / ms us
390 ysh-string "x is $x" $"x is $x" r'[a-z]\n'
391 u'line\n' b'byte \yff'
392 triple-quoted """ $""" r''' u''' b'''
393 str-template ^"$a and $b" for Str::replace()
394 list-literal ['one', 'two', 3] :| unquoted words |
395 dict-literal {name: 'bob'} {a, b}
396 range 1 .. n+1
397 block-expr ^(echo $PWD)
398 expr-literal ^[1 + 2*3]
399 X expr-sub $[myobj]
400 X expr-splice @[myobj]
401 [Operators] op-precedence Like Python
402 concat s1 ++ s2, L1 ++ L2
403 ysh-equals === !== ~== is, is not
404 ysh-in in, not in
405 ysh-compare < <= > >= (numbers only)
406 ysh-logical not and or
407 ysh-arith + - * / // % **
408 ysh-bitwise ~ & | ^ << >>
409 ysh-ternary '+' if x >= 0 else '-'
410 ysh-index s[0] mylist[3] mydict['key']
411 ysh-attr mydict.key
412 ysh-slice a[1:-1] s[1:-1]
413 func-call f(x, y; ...named)
414 thin-arrow mylist->pop()
415 fat-arrow mystr => startsWith('prefix')
416 match-ops ~ !~ ~~ !~~
417 [Eggex] re-literal / d+ ; re-flags ; ERE /
418 re-primitive %zero 'sq'
419 class-literal [c a-z 'abc' @str_var \\ \xFF \u{3bc}]
420 named-class dot digit space word d s w
421 re-repeat d? d* d+ d{3} d{2,4}
422 re-compound seq1 seq2 alt1|alt2 (expr1 expr2)
423 re-capture <capture d+ as name: int>
424 re-splice Subpattern @subpattern
425 re-flags reg_icase reg_newline
426 X re-multiline ///
427)zZXx");
428
429GLOBAL_STR(gStr23, R"zZXx(
430 Front End <a class="group-link" href="chap-front-end.html">front-end</a>
431
432
433 [Usage] oils-usage ysh-usage
434 [Lexing] ascii-whitespace [ \t\r\n]
435 doc-comment ### multiline-command ...
436 [Tools] cat-em
437)zZXx");
438
439GLOBAL_STR(gStr24, R"zZXx(
440 Other Mini Languages <a class="group-link" href="chap-mini-lang.html">mini-lang</a>
441
442
443 [Patterns] glob-pat *.py
444 [Other Sublang] braces {alice,bob}@example.com
445)zZXx");
446
447GLOBAL_STR(gStr25, R"zZXx(
448 Global Shell Options <a class="group-link" href="chap-option.html">option</a>
449
450
451 [Groups] strict:all ysh:upgrade ysh:all
452 [YSH Details] opts-redefine opts-internal
453)zZXx");
454
455GLOBAL_STR(gStr26, R"zZXx(
456 Plugins and Hooks <a class="group-link" href="chap-plugin.html">plugin</a>
457
458
459 [YSH] renderPrompt()
460)zZXx");
461
462GLOBAL_STR(gStr27, R"zZXx(
463 Special Variables <a class="group-link" href="chap-special-var.html">special-var</a>
464
465
466 [YSH Vars] ARGV X ENV X _ESCAPE
467 _this_dir
468 [YSH Status] _error
469 _pipeline_status _process_sub_status
470 [YSH Tracing] SHX_indent SHX_punct SHX_pid_str
471 [YSH read] _reply
472 [History] YSH_HISTFILE
473 [Oils VM] OILS_VERSION
474 OILS_GC_THRESHOLD OILS_GC_ON_EXIT
475 OILS_GC_STATS OILS_GC_STATS_FD
476 LIB_YSH
477 [Float] NAN INFINITY
478)zZXx");
479
480GLOBAL_STR(gStr28, R"zZXx(
481 Standard Library<a class="group-link" href="chap-stdlib.html">stdlib</a>
482
483
484 [math] abs() max() min() X round()
485 sum()
486 [list] all() any() repeat()
487 [yblocks] yb-capture yb-capture-2
488 [args] parser flag arg rest
489 parseArgs()
490)zZXx");
491
492GLOBAL_STR(gStr29, R"zZXx(
493 Types and Methods <a class="group-link" href="chap-type-method.html">type-method</a>
494
495
496 [Atom Types] Null Bool
497 [Number Types] Int Float
498 [Str] X find() replace()
499 trim() trimStart() trimEnd()
500 startsWith() endsWith()
501 upper() lower()
502 search() leftMatch()
503 [List] List/append() pop() extend() indexOf()
504 X insert() X remove() reverse()
505 [Dict] keys() values() X get() erase()
506 X inc() X accum()
507 [Range]
508 [Eggex]
509 [Match] group() start() end()
510 X groups() X groupDict()
511 [Place] setValue()
512 [Code Types] Expr Command
513 BuiltinFunc BoundFunc
514X [Func] name() location() toJson()
515X [Proc] name() location() toJson()
516X [Module] name() filename()
517 [IO] eval() captureStdout()
518 promptVal()
519 X time() X strftime()
520 X glob()
521)zZXx");
522
523GLOBAL_STR(gStr30, R"zZXx(bin/ysh is the shell with data tYpes, influenced by pYthon, JavaScript, ...
524
525Usage: ysh FLAG* SCRIPT ARG*
526 ysh FLAG* -c COMMAND ARG*
527 ysh FLAG*
528
529`bin/ysh` is the same as `bin/osh` with a the `ysh:all` option group set. So
530`bin/ysh` also accepts shell flags.
531
532 ysh -c 'echo hi'
533 ysh myscript.ysh
534 echo 'echo hi' | ysh
535)zZXx");
536
537GLOBAL_STR(gStr31, R"zZXx(
538 Word Language <a class="group-link" href="chap-word-lang.html">word-lang</a>
539
540
541 [Quotes] ysh-string "x is $x" $"x is $x" r'[a-z]\n'
542 u'line\n' b'byte \yff'
543 triple-quoted """ $""" r''' u''' b'''
544 X tagged-str "<span id=$x>"html
545 [Substitutions] expr-sub echo $[42 + a[i]]
546 expr-splice echo @[split(x)]
547 var-splice @myarray @ARGV
548 command-sub @(cat my-j8-lines.txt)
549 [Formatting] X ysh-printf ${x %.3f}
550 X ysh-format ${x|html}
551)zZXx");
552
553GLOBAL_STR(gStr32, R"zZXx(
554 YSH Command Language Keywords <a class="group-link" href="chap-ysh-cmd.html">ysh-cmd</a>
555
556
557 [Assignment] const var Declare variables
558 setvar setvar a[i] = 42
559 setglobal setglobal d.key = 'foo'
560 [Expression] equal = = 1 + 2*3
561 call call mylist->append(42)
562 [Definitions] proc proc p (s, ...rest) {
563 typed proc p (; typed, ...rest; n=0; b) {
564 func func f(x; opt1, opt2) { return (x + 1) }
565 ysh-return return (myexpr)
566)zZXx");
567
568GLOBAL_STR(gStr33, R"zZXx(func identity(x) {
569 ## The identity function. Returns its argument.
570
571 return (x)
572}
573)zZXx");
574
575GLOBAL_STR(gStr34, R"zZXx(# Can we define methods in pure YSH?
576#
577# (mylist->find(42) !== -1)
578#
579# instead of
580#
581# ('42' in mylist)
582#
583# Because 'in' is for Dict
584
585func find (haystack List, needle) {
586 for i, x in (haystack) {
587 if (x === needle) {
588 return (i)
589 }
590 }
591 return (-1)
592}
593)zZXx");
594
595GLOBAL_STR(gStr35, R"zZXx(# Bash strict mode, updated for 2024
596
597set -o nounset
598set -o pipefail
599set -o errexit
600shopt -s inherit_errexit
601shopt -s strict:all 2>/dev/null || true # dogfood for OSH
602
603)zZXx");
604
605GLOBAL_STR(gStr36, R"zZXx(# Library to turn a shell file into a "BYO test server"
606#
607# Usage:
608#
609# # from both bash and OSH
610# if test -z "$LIB_OSH"; then LIB_OSH=stdlib/osh; fi
611# source $LIB_OSH/byo-server-lib.sh
612#
613# The client creates a clean process state and directory state for each tests.
614#
615# (This file requires compgen -A, and maybe declare -f, so it's not POSIX
616# shell.)
617
618: ${LIB_OSH:-stdlib/osh}
619source $LIB_OSH/two.sh
620
621# List all functions defined in this file (and not in sourced files).
622_bash-print-funcs() {
623 ### Print shell functions in this file that don't start with _ (bash reflection)
624
625 local funcs
626 funcs=($(compgen -A function))
627
628 # extdebug makes `declare -F` print the file path, but, annoyingly, only
629 # if you pass the function names as arguments.
630 shopt -s extdebug
631
632 # bash format:
633 # func1 1 path1
634 # func2 2 path2 # where 2 is the linen umber
635
636 #declare -F "${funcs[@]}"
637
638 # TODO: do we need to normalize the LHS and RHS of $3 == path?
639 declare -F "${funcs[@]}" | awk -v "path=$0" '$3 == path { print $1 }'
640
641 shopt -u extdebug
642}
643
644_gawk-print-funcs() {
645 ### Print shell functions in this file that don't start with _ (awk parsing)
646
647 # Using gawk because it has match()
648 # - doesn't start with _
649
650 # space = / ' '* /
651 # shfunc = / %begin
652 # <capture !['_' ' '] ![' ']*>
653 # '()' space '{' space
654 # %end /
655 # docstring = / %begin
656 # space '###' ' '+
657 # <capture dot*>
658 # %end /
659 gawk '
660 match($0, /^([^_ ][^ ]*)\(\)[ ]*{[ ]*$/, m) {
661 #print NR " shfunc " m[1]
662 print m[1]
663 #print m[0]
664 }
665
666 match($0, /^[ ]*###[ ]+(.*)$/, m) {
667 print NR " docstring " m[1]
668 }
669' $0
670}
671
672_print-funcs() {
673 _bash-print-funcs
674 return
675
676 # TODO: make gawk work, with docstrings
677 if command -v gawk > /dev/null; then
678 _gawk-print-funcs
679 else
680 _bash-print-funcs
681 fi
682}
683
684
685byo-maybe-run() {
686 local command=${BYO_COMMAND:-}
687
688 case $command in
689 '')
690 # Do nothing if it's not specified
691 return
692 ;;
693
694 detect)
695 # all the commands supported, except 'detect'
696 echo list-tests
697 echo run-test
698
699 exit 66 # ASCII code for 'B' - what the protocol specifies
700 ;;
701
702 list-tests)
703 # TODO: use _bash-print-funcs? This fixes the transitive test problem,
704 # which happened in soil/web-remote-test.sh
705 # But it should work with OSH, not just bash! We need shopt -s extdebug
706 compgen -A function | grep '^test-'
707 exit 0
708 ;;
709
710 run-test)
711 local test_name=${BYO_ARG:-}
712 if test -z "$test_name"; then
713 die "BYO run-test: Expected BYO_ARG"
714 fi
715
716 # Avoid issues polluting recursive calls!
717 unset BYO_COMMAND BYO_ARG
718
719 # Shell convention: we name functions test-*
720 "$test_name"
721
722 # Only run if not set -e. Either way it's equivalent
723 exit $?
724 ;;
725
726 *)
727 die "Invalid BYO command '$command'"
728 ;;
729 esac
730
731 # Do nothing if BYO_COMMAND is not set.
732 # The program continues to its "main".
733}
734
735byo-must-run() {
736 local command=${BYO_COMMAND:-}
737 if test -z "$command"; then
738 die "Expected BYO_COMMAND= in environment"
739 fi
740
741 byo-maybe-run
742}
743)zZXx");
744
745GLOBAL_STR(gStr37, R"zZXx(#!/usr/bin/env bash
746#
747# Testing library for bash and OSH.
748#
749# Capture status/stdout/stderr, and nq-assert those values.
750
751: ${LIB_OSH=stdlib/osh}
752source $LIB_OSH/two.sh
753
754nq-assert() {
755 ### Assertion with same syntax as shell 'test'
756
757 if ! test "$@"; then
758 die "line ${BASH_LINENO[0]}: nq-assert $(printf '%q ' "$@") failed"
759 fi
760}
761
762# Problem: we want to capture status and stdout at the same time
763#
764# We use:
765#
766# __stdout=$(set -o errexit; "$@")
767# __status=$?
768#
769# However, we lose the trailing \n, since that's how command subs work.
770
771# Here is another possibility:
772#
773# shopt -s lastpipe # need this too
774# ( set -o errexit; "$@" ) | read -r -d __stdout
775# __status=${PIPESTATUS[0]}
776# shopt -u lastpipe
777#
778# But this feels complex for just the \n issue, which can be easily worked
779# around.
780
781nq-run() {
782 ### capture status only
783
784 local -n out_status=$1
785 shift
786
787 local __status
788
789 # Tricky: turn errexit off so we can capture it, but turn it on against
790 set +o errexit
791 ( set -o errexit; "$@" )
792 __status=$?
793 set -o errexit
794
795 out_status=$__status
796}
797
798nq-capture() {
799 ### capture status and stdout
800
801 local -n out_status=$1
802 local -n out_stdout=$2
803 shift 2
804
805 local __status
806 local __stdout
807
808 # Tricky: turn errexit off so we can capture it, but turn it on against
809 set +o errexit
810 __stdout=$(set -o errexit; "$@")
811 __status=$?
812 set -o errexit
813
814 out_status=$__status
815 out_stdout=$__stdout
816}
817
818nq-capture-2() {
819 ### capture status and stderr
820
821 # This is almost identical to the above
822
823 local -n out_status=$1
824 local -n out_stderr=$2
825 shift 2
826
827 local __status
828 local __stderr
829
830 # Tricky: turn errexit off so we can capture it, but turn it on against
831 set +o errexit
832 __stderr=$(set -o errexit; "$@" 2>&1)
833 __status=$?
834 set -o errexit
835
836 out_status=$__status
837 out_stderr=$__stderr
838}
839
840# 'byo test' can set this?
841: ${NQ_TEST_TEMP=/tmp}
842
843nq-redir() {
844 ### capture status and stdout
845
846 local -n out_status=$1
847 local -n out_stdout_file=$2
848 shift 2
849
850 local __status
851 local __stdout_file=$NQ_TEST_TEMP/nq-redir-$$.txt
852
853 # Tricky: turn errexit off so we can capture it, but turn it on against
854 set +o errexit
855 ( set -o errexit; "$@" ) > $__stdout_file
856 __status=$?
857 set -o errexit
858
859 out_status=$__status
860 out_stdout_file=$__stdout_file
861}
862
863nq-redir-2() {
864 ### capture status and stdout
865
866 local -n out_status=$1
867 local -n out_stderr_file=$2
868 shift 2
869
870 local __status
871 local __stderr_file=$NQ_TEST_TEMP/nq-redir-$$.txt
872
873 # Tricky: turn errexit off so we can capture it, but turn it on against
874 set +o errexit
875 ( set -o errexit; "$@" ) 2> $__stderr_file
876 __status=$?
877 set -o errexit
878
879 out_status=$__status
880 out_stderr_file=$__stderr_file
881}
882)zZXx");
883
884GLOBAL_STR(gStr38, R"zZXx(#!/usr/bin/env bash
885#
886# Common shell functions for task scripts.
887#
888# Usage:
889# source $LIB_OSH/task-five.sh
890#
891# test-foo() { # define task functions
892# echo foo
893# }
894# task-five "$@"
895
896# Definition of a "task"
897#
898# - File invokes task-five "$@"
899# - or maybe you can look at its source
900# - It's a shell function
901# - Has ### docstring
902# - Doesn't start with _
903
904: ${LIB_OSH=stdlib/osh}
905source $LIB_OSH/byo-server.sh
906
907_show-help() {
908 # TODO:
909 # - Use awk to find comments at the top of the file?
910 # - Use OSH to extract docstrings
911 # - BYO_COMMAND=list-tasks will reuse that logic? It only applies to the
912 # current file, not anything in a different file?
913
914 echo "Usage: $0 TASK_NAME ARGS..."
915 echo
916 echo "To complete tasks, run:"
917 echo " source devtools/completion.bash"
918 echo
919 echo "Tasks:"
920
921 if command -v column >/dev/null; then
922 _print-funcs | column
923 else
924 _print-funcs
925 fi
926}
927
928task-five() {
929 # Respond to BYO_COMMAND=list-tasks, etc. All task files need this.
930 byo-maybe-run
931
932 case ${1:-} in
933 ''|--help|-h)
934 _show-help
935 exit 0
936 ;;
937 esac
938
939 if ! declare -f "$1" >/dev/null; then
940 echo "$0: '$1' isn't an action in this task file. Try '$0 --help'"
941 exit 1
942 fi
943
944 "$@"
945}
946)zZXx");
947
948GLOBAL_STR(gStr39, R"zZXx(# Two functions I actually use, all the time.
949#
950# To keep depenedencies small, this library will NEVER grow other functions
951# (and is named to imply that.)
952#
953# Usage:
954# source --builtin two.sh
955#
956# Examples:
957# log 'hi'
958# die 'expected a number'
959
960if command -v source-guard >/dev/null; then # include guard for YSH
961 source-guard two || return 0
962fi
963
964log() {
965 ### Write a message to stderr.
966 echo "$@" >&2
967}
968
969die() {
970 ### Write an error message with the script name, and exit with status 1.
971 log "$0: fatal: $@"
972 exit 1
973}
974
975)zZXx");
976
977GLOBAL_STR(gStr40, R"zZXx(# These were helpful while implementing args.ysh
978# Maybe we will want to export them in a prelude so that others can use them too?
979#
980# Prior art: Rust has `todo!()` which is quite nice. Other languages allow
981# users to `raise NotImplmentedError()`.
982
983# Andy comments:
984# - 'pass' can be : or true in shell. It's a little obscure / confusing, but
985# there is an argument for minimalism. Although I prefer words like 'true',
986# and that already means something.
987# - UPDATE: we once took 'pass' as a keyword, but users complained because
988# there is a command 'pass'. So we probably can't have this by default.
989# Need to discuss source --builtin.
990
991# - todo could be more static? Rust presumably does it at compile time
992
993proc todo () {
994 ## Raises a not implemented error when run.
995 error ("TODO: not implemented") # TODO: is error code 1 ok?
996}
997
998proc pass () {
999 ## Use when you want to temporarily leave a block empty.
1000 _ null
1001}
1002)zZXx");
1003
1004GLOBAL_STR(gStr41, R"zZXx(# testing.ysh
1005#
1006# Usage:
1007# source --builtin testing.sh
1008#
1009# func f(x) { return (x + 1) }
1010#
1011# describe foo {
1012# assert (43 === f(42))
1013# }
1014#
1015# if is-main {
1016# run-tests @ARGV # --filter
1017# }
1018
1019module stdlib/testing || return 0
1020
1021source --builtin args.ysh
1022
1023proc assert ( ; cond ; fail_message='default fail message') {
1024 echo 'hi from assert'
1025
1026 = cond
1027
1028 # I think this might be ready now?
1029
1030 var val = evalExpr(cond)
1031
1032 echo
1033 echo 'value'
1034 = val
1035 pp line (val)
1036
1037 = fail_message
1038
1039 if (val) {
1040 echo 'OK'
1041 } else {
1042 var m = evalExpr(fail_message)
1043 echo "FAIL - this is where we extract the string - $m"
1044 }
1045}
1046
1047proc test-assert {
1048 var x = 42
1049 assert [42 === x]
1050}
1051
1052proc test-expr ( ; expr ) {
1053 echo 'expr'
1054 pp line (expr)
1055}
1056
1057proc test-named ( ; ; n=^[99] ) {
1058 echo 'n'
1059 pp line (n)
1060}
1061
1062# What happens when there are duplicate test IDs?
1063#
1064# Also I think filter by "$test_id/$case_id"
1065
1066proc __it (case_id ; ; ; block) {
1067 # This uses a clean directory
1068 echo TODO
1069}
1070
1071# is this accessible to users?
1072# It can contain a global list of things to run
1073
1074# Naming convention: a proc named 'describe' mutates a global named _describe?
1075# Or maybe _describe_list ?
1076
1077var _describe_list = []
1078
1079proc describe (test_id ; ; ; block) {
1080 echo describe
1081 #= desc
1082
1083 # TODO:
1084 # - need append
1085 # - need ::
1086 # _ _describe->append(cmd)
1087 #
1088 # Need to clean this up
1089 # append (_describe, cmd) # does NOT work!
1090
1091 call _describe_list->append(block)
1092}
1093
1094proc Args {
1095 echo TODO
1096}
1097
1098# Problem: this creates a global variable?
1099Args (&spec) {
1100 flag --filter 'Regex of test descriptions'
1101}
1102
1103proc run-tests {
1104 var opt, i = parseArgs(spec, ARGV)
1105
1106 # TODO:
1107 # - parse --filter foo, which you can use eggex for!
1108
1109 for cmd in (_describe) {
1110 # TODO: print filename and 'describe' name?
1111 try {
1112 eval (cmd)
1113 }
1114 if (_status !== 0) {
1115 echo 'failed'
1116 }
1117 }
1118}
1119)zZXx");
1120
1121GLOBAL_STR(gStr42, R"zZXx(# args.ysh
1122#
1123# Usage:
1124# source --builtin args.sh
1125#
1126# parser (&spec) {
1127# flag -v --verbose (help="Verbosely") # default is Bool, false
1128#
1129# flag -P --max-procs ('int', default=-1, doc='''
1130# Run at most P processes at a time
1131# ''')
1132#
1133# flag -i --invert ('bool', default=true, doc='''
1134# Long multiline
1135# Description
1136# ''')
1137#
1138# arg src (help='Source')
1139# arg dest (help='Dest')
1140# arg times (help='Foo')
1141#
1142# rest files
1143# }
1144#
1145# var args = parseArgs(spec, ARGV)
1146#
1147# echo "Verbose $[args.verbose]"
1148
1149# TODO: See list
1150# - It would be nice to keep `flag` and `arg` private, injecting them into the
1151# proc namespace only within `Args`
1152# - We need "type object" to replace the strings 'int', 'bool', etc.
1153# - flag builtin:
1154# - handle only long flag or only short flag
1155# - flag aliases
1156
1157proc parser (; place ; ; block_def) {
1158 ## Create an args spec which can be passed to parseArgs.
1159 ##
1160 ## Example:
1161 ##
1162 ## # NOTE: &spec will create a variable named spec
1163 ## parser (&spec) {
1164 ## flag -v --verbose ('bool')
1165 ## }
1166 ##
1167 ## var args = parseArgs(spec, ARGV)
1168
1169 var p = {flags: [], args: []}
1170 ctx push (p; ; block_def)
1171
1172 # Validate that p.rest = [name] or null and reduce p.rest into name or null.
1173 if ('rest' in p) {
1174 if (len(p.rest) > 1) {
1175 error '`rest` was called more than once' (code=3)
1176 } else {
1177 setvar p.rest = p.rest[0]
1178 }
1179 } else {
1180 setvar p.rest = null
1181 }
1182
1183 var names = {}
1184 for items in ([p.flags, p.args]) {
1185 for x in (items) {
1186 if (x.name in names) {
1187 error "Duplicate flag/arg name $[x.name] in spec" (code=3)
1188 }
1189
1190 setvar names[x.name] = null
1191 }
1192 }
1193
1194 # TODO: what about `flag --name` and then `arg name`?
1195
1196 call place->setValue(p)
1197}
1198
1199proc flag (short, long ; type='bool' ; default=null, help=null) {
1200 ## Declare a flag within an `arg-parse`.
1201 ##
1202 ## Examples:
1203 ##
1204 ## arg-parse (&spec) {
1205 ## flag -v --verbose
1206 ## flag -n --count ('int', default=1)
1207 ## flag -f --file ('str', help="File to process")
1208 ## }
1209
1210 # bool has a default of false, not null
1211 if (type === 'bool' and default === null) {
1212 setvar default = false
1213 }
1214
1215 # TODO: validate `type`
1216
1217 # TODO: Should use "trimPrefix"
1218 var name = long[2:]
1219
1220 ctx emit flags ({short, long, name, type, default, help})
1221}
1222
1223proc arg (name ; ; help=null) {
1224 ## Declare a positional argument within an `arg-parse`.
1225 ##
1226 ## Examples:
1227 ##
1228 ## arg-parse (&spec) {
1229 ## arg name
1230 ## arg config (help="config file path")
1231 ## }
1232
1233 ctx emit args ({name, help})
1234}
1235
1236proc rest (name) {
1237 ## Take the remaining positional arguments within an `arg-parse`.
1238 ##
1239 ## Examples:
1240 ##
1241 ## arg-parse (&grepSpec) {
1242 ## arg query
1243 ## rest files
1244 ## }
1245
1246 # We emit instead of set to detect multiple invocations of "rest"
1247 ctx emit rest (name)
1248}
1249
1250func parseArgs(spec, argv) {
1251 ## Given a spec created by `parser`. Parse an array of strings `argv` per
1252 ## that spec.
1253 ##
1254 ## See `parser` for examples of use.
1255
1256 var i = 0
1257 var positionalPos = 0
1258 var argc = len(argv)
1259 var args = {}
1260 var rest = []
1261
1262 var value
1263 var found
1264 while (i < argc) {
1265 var arg = argv[i]
1266 if (arg->startsWith('-')) {
1267 setvar found = false
1268
1269 for flag in (spec.flags) {
1270 if ( (flag.short and flag.short === arg) or
1271 (flag.long and flag.long === arg) ) {
1272 case (flag.type) {
1273 ('bool') | (null) { setvar value = true }
1274 int {
1275 setvar i += 1
1276 if (i >= len(argv)) {
1277 error "Expected integer after '$arg'" (code=2)
1278 }
1279
1280 try { setvar value = int(argv[i]) }
1281 if (_status !== 0) {
1282 error "Expected integer after '$arg', got '$[argv[i]]'" (code=2)
1283 }
1284 }
1285 }
1286
1287 setvar args[flag.name] = value
1288 setvar found = true
1289 break
1290 }
1291 }
1292
1293 if (not found) {
1294 error "Unknown flag '$arg'" (code=2)
1295 }
1296 } elif (positionalPos >= len(spec.args)) {
1297 if (not spec.rest) {
1298 error "Too many arguments, unexpected '$arg'" (code=2)
1299 }
1300
1301 call rest->append(arg)
1302 } else {
1303 var pos = spec.args[positionalPos]
1304 setvar positionalPos += 1
1305 setvar value = arg
1306 setvar args[pos.name] = value
1307 }
1308
1309 setvar i += 1
1310 }
1311
1312 if (spec.rest) {
1313 setvar args[spec.rest] = rest
1314 }
1315
1316 # Set defaults for flags
1317 for flag in (spec.flags) {
1318 if (flag.name not in args) {
1319 setvar args[flag.name] = flag.default
1320 }
1321 }
1322
1323 # Raise error on missing args
1324 for arg in (spec.args) {
1325 if (arg.name not in args) {
1326 error "Usage Error: Missing required argument $[arg.name]" (code=2)
1327 }
1328 }
1329
1330 return (args)
1331}
1332)zZXx");
1333
1334GLOBAL_STR(gStr43, R"zZXx(func any(list) {
1335 ### Returns true if any value in the list is truthy.
1336 # Empty list: returns false
1337
1338 for item in (list) {
1339 if (item) {
1340 return (true)
1341 }
1342 }
1343 return (false)
1344}
1345
1346func all(list) {
1347 ## Returns true if all values in the list are truthy.
1348 # Empty list: returns true
1349
1350 for item in (list) {
1351 if (not item) {
1352 return (false)
1353 }
1354 }
1355 return (true)
1356}
1357
1358func sum(list; start=0) {
1359 ### Returns the sum of all elements in the list.
1360 # Empty list: returns 0
1361
1362 var sum = start
1363 for item in (list) {
1364 setvar sum += item
1365 }
1366 return (sum)
1367}
1368
1369func repeat(x, n) {
1370 ### Returns a list with the given string or list repeated
1371
1372 # Like Python's 'foo'*3 or ['foo', 'bar']*3
1373 # negative numbers are like 0 in Python
1374
1375 var t = type(x)
1376 case (t) {
1377 Str {
1378 var parts = []
1379 for i in (0 .. n) {
1380 call parts->append(x)
1381 }
1382 return (join(parts))
1383 }
1384 List {
1385 var result = []
1386 for i in (0 .. n) {
1387 call result->extend(x)
1388 }
1389 return (result)
1390 }
1391 (else) {
1392 error "Expected Str or List, got $t"
1393 }
1394 }
1395}
1396)zZXx");
1397
1398GLOBAL_STR(gStr44, R"zZXx(func __math_select(list, cmp) {
1399 ## Internal helper for `max` and `min`.
1400 ##
1401 ## NOTE: If `list` is empty, then an error is thrown.
1402
1403 if (len(list) === 0) {
1404 error "Unexpected empty list" (code=3)
1405 }
1406
1407 if (len(list) === 1) {
1408 return (list[0])
1409 }
1410
1411 var match = list[0]
1412 for i in (1 .. len(list)) {
1413 setvar match = cmp(list[i], match)
1414 }
1415 return (match)
1416}
1417
1418func max(...args) {
1419 ## Compute the maximum of 2 or more values.
1420 ##
1421 ## `max` takes two different signatures:
1422 ## - `max(a, b)` to return the maximum of `a`, `b`
1423 ## - `max(list)` to return the greatest item in the `list`
1424 ##
1425 ## So, for example:
1426 ##
1427 ## max(1, 2) # => 2
1428 ## max([1, 2, 3]) # => 3
1429
1430 case (len(args)) {
1431 (1) { return (__math_select(args[0], max)) }
1432 (2) {
1433 if (args[0] > args[1]) {
1434 return (args[0])
1435 } else {
1436 return (args[1])
1437 }
1438 }
1439 (else) { error "max expects 1 or 2 args" (code=3) }
1440 }
1441}
1442
1443func min(...args) {
1444 ## Compute the minimum of 2 or more values.
1445 ##
1446 ## `min` takes two different signatures:
1447 ## - `min(a, b)` to return the minimum of `a`, `b`
1448 ## - `min(list)` to return the least item in the `list`
1449 ##
1450 ## So, for example:
1451 ##
1452 ## min(2, 3) # => 2
1453 ## max([1, 2, 3]) # => 1
1454
1455 case (len(args)) {
1456 (1) { return (__math_select(args[0], min)) }
1457 (2) {
1458 if (args[0] < args[1]) {
1459 return (args[0])
1460 } else {
1461 return (args[1])
1462 }
1463 }
1464 (else) { error "min expects 1 or 2 args" (code=3) }
1465 }
1466}
1467
1468func abs(x) {
1469 ## Compute the absolute (positive) value of a number (float or int).
1470
1471 if (x < 0) {
1472 return (-x)
1473 } else {
1474 return (x)
1475 }
1476}
1477)zZXx");
1478
1479GLOBAL_STR(gStr45, R"zZXx(# stream.ysh
1480#
1481# Usage:
1482# source --builtin stream.ysh
1483#
1484# For reading lines, decoding, extracting, splitting
1485
1486# make this file a test server
1487source $LIB_OSH/byo-server.sh
1488
1489source $LIB_YSH/args.ysh
1490
1491proc slurp-by (; num_lines) {
1492 # TODO: (stdin)
1493 for line in (stdin) {
1494 echo TODO
1495 }
1496}
1497
1498# Note:
1499# - these are all the same algorithm
1500# - also word, block, etc. are all optional
1501
1502proc each-line (...words; template=null; ; block=null) {
1503 # TODO:
1504 # parse --j8 --max-jobs flag
1505
1506 # parse template_str as string
1507 # TODO: this is dangerous though ... because you can execute code
1508 # I think you need a SAFE version
1509
1510 # evaluate template string expression - I guess that allows $(echo hi) and so
1511 # forth
1512
1513 # evaluate block with _line binding
1514 # block: execute in parallel with --max-jobs
1515
1516 for line in (stdin) {
1517 echo TODO
1518 }
1519}
1520
1521proc test-each-line {
1522 echo 'TODO: need basic test runner'
1523
1524 # ysh-tool test stream.ysh
1525 #
1526 # Col
1527
1528
1529}
1530
1531proc each-row (; ; block) {
1532 echo TODO
1533}
1534
1535proc split-by (; ifs=null; block) {
1536 echo TODO
1537}
1538
1539proc if-split-by (; ifs=null; block) {
1540 echo TODO
1541}
1542
1543proc chop () {
1544 ### alias for if-split-by
1545 echo TODO
1546}
1547
1548proc must-match (; pattern; block) {
1549 echo TODO
1550}
1551
1552proc if-match (; pattern; block) {
1553 echo TODO
1554}
1555
1556# Protocol:
1557#
1558# - The file lists its tests the "actions"
1559# - Then the test harness runs them
1560# - But should it be ENV vars
1561#
1562# - BYO_LIST_TESTS=1
1563# - BYO_RUN_TEST=foo
1564# - $PWD is a CLEAN temp dir, the process doesn't have to do anything
1565
1566# - silent on success, but prints file on output
1567# - OK this makes sense
1568#
1569# The trivial test in Python:
1570#
1571# from test import byo
1572# byo.maybe_main()
1573#
1574# bash library:
1575# source --builtin byo-server.sh
1576#
1577# byo-maybe-main # reads env variables, and then exits
1578#
1579# source --builtin assertions.ysh
1580#
1581# assert-ok 'echo hi'
1582# assert-stdout 'hi' 'echo -n hi'
1583#
1584# "$@"
1585#
1586# Run all tests
1587# util/byo-client.sh run-tests $YSH stdlib/table.ysh
1588# util/byo-client.sh run-tests -f x $YSH stdlib/table.ysh
1589
1590# Clean process
1591# Clean working dir
1592
1593#
1594# Stream Protocol:
1595# #.byo - is this she-dot, that's for a file
1596# Do we need metadata?
1597#
1598
1599# The harness
1600#
1601# It's process based testing.
1602#
1603# Test runner process: bash or OSH (unlike sharness!)
1604# Tested process: any language - bash,
1605#
1606# Key point: you don't have to quote shell code?
1607
1608list-byo-tests() {
1609 echo TODO
1610}
1611
1612run-byo-tests() {
1613 # source it
1614 echo TODO
1615}
1616
1617byo-maybe-run
1618)zZXx");
1619
1620GLOBAL_STR(gStr46, R"zZXx(# table.ysh - Library for tables.
1621#
1622# Usage:
1623# source --builtin table.ysh
1624
1625# make this file a test server
1626source --builtin osh/byo-server.sh
1627
1628proc table (...words; place; ; block) {
1629 var n = len(words)
1630
1631 # TODO: parse flags
1632 #
1633 # --by-row
1634 # --by-col
1635 #
1636 # Place is optional
1637
1638 if (n === 0) {
1639 echo TODO
1640 return
1641 }
1642
1643 var action = words[0]
1644
1645 # textual operations
1646 case (action) {
1647 cat {
1648 echo todo
1649 }
1650 align {
1651 echo todo
1652 }
1653 tabify {
1654 echo todo
1655 }
1656 tabify {
1657 echo todo
1658 }
1659 header {
1660 echo todo
1661 }
1662 slice {
1663 # this has typed args
1664 # do we do some sort of splat?
1665 echo todo
1666 }
1667 to-tsv {
1668 echo todo
1669 }
1670 }
1671
1672 echo TODO
1673}
1674
1675proc test-table {
1676 return
1677
1678 table (&files1) {
1679 cols num_bytes path
1680 type Int Str
1681
1682 row 10 README.md
1683 row 12 main.py
1684
1685 row (12, 'lib.py')
1686 row (num_bytes=12, path='util.py')
1687 }
1688
1689 # 2 columns - The default is by column?
1690 assert ['Dict' === type(files1)]
1691 assert [2 === len(files1)]
1692
1693 # Same table
1694 table --by-row (&files2) {
1695 cols num_bytes path
1696 type Int Str
1697
1698 row 10 README.md
1699 row 12 main.py
1700
1701 row (12, 'lib.py')
1702 row (num_bytes=12, path='util.py')
1703 }
1704
1705 # 4 rows
1706 assert ['List' === type(files2)]
1707 assert [4 === len(files2)]
1708}
1709
1710# "subcommands" of the dialect
1711
1712proc cols (...names) {
1713 # cols name age
1714 echo TODO
1715}
1716
1717proc types (...types) {
1718 # types - Int? Str?
1719 echo TODO
1720}
1721
1722proc attr (name; ...values) {
1723 # attr units ('-', 'secs')
1724 echo TODO
1725}
1726
1727# is this allowed outside table {} blocks too?
1728proc row {
1729 echo TODO
1730}
1731
1732#
1733# dplyr names
1734#
1735
1736# TODO: can we parse select?
1737
1738proc where {
1739 echo
1740}
1741
1742# TODO: should be able to test argv[0] or something
1743# Or pass to _mutate-transmute
1744
1745proc mutate {
1746 echo TODO
1747}
1748
1749proc transmute {
1750 echo TODO
1751}
1752
1753proc rename {
1754 echo TODO
1755}
1756
1757proc group-by {
1758 echo TODO
1759}
1760
1761proc sort-by {
1762 echo TODO
1763}
1764
1765proc summary {
1766 echo TODO
1767}
1768
1769byo-maybe-run
1770)zZXx");
1771
1772GLOBAL_STR(gStr47, R"zZXx(#!/usr/bin/env bash
1773#
1774# Testing library for bash and OSH.
1775#
1776# Capture status/stdout/stderr, and nq-assert those values.
1777
1778#module yblocks || return 0
1779
1780: ${LIB_OSH=stdlib/osh}
1781source $LIB_OSH/two.sh
1782
1783# There is no yb-run, because you can just use try { } and inspect _error.code
1784# There is no yb-redir, because you can just use try >$tmp { } and inspect _error.code
1785
1786proc yb-capture(; out; ; block) {
1787 ### capture status and stderr
1788
1789 var stdout = ''
1790 try {
1791 eval (block) | read --all (&stdout)
1792 }
1793 # TODO: if 'block' contains a pipeline, we lose this magic var
1794 var result = {status: _pipeline_status[0], stdout}
1795
1796 #echo 'result-1'
1797 #pp test_ (result)
1798
1799 call out->setValue(result)
1800}
1801
1802proc yb-capture-2(; out; ; block) {
1803 ### capture status and stderr
1804
1805 var stderr = ''
1806 try {
1807 eval (block) 2>&1 | read --all (&stderr)
1808 }
1809 #pp test_ (_pipeline_status)
1810
1811 var result = {status: _pipeline_status[0], stderr}
1812 #echo 'result-2'
1813 #pp test_ (result)
1814
1815 call out->setValue(result)
1816}
1817)zZXx");
1818
1819
1820
1821TextFile array[] = {
1822 {.rel_path = "_devbuild/help/data-errors", .contents = gStr0},
1823 {.rel_path = "_devbuild/help/data-front-end", .contents = gStr1},
1824 {.rel_path = "_devbuild/help/data-j8-notation", .contents = gStr2},
1825 {.rel_path = "_devbuild/help/help", .contents = gStr3},
1826 {.rel_path = "_devbuild/help/oils-usage", .contents = gStr4},
1827 {.rel_path = "_devbuild/help/osh-builtin-cmd", .contents = gStr5},
1828 {.rel_path = "_devbuild/help/osh-chapters", .contents = gStr6},
1829 {.rel_path = "_devbuild/help/osh-cmd-lang", .contents = gStr7},
1830 {.rel_path = "_devbuild/help/osh-front-end", .contents = gStr8},
1831 {.rel_path = "_devbuild/help/osh-mini-lang", .contents = gStr9},
1832 {.rel_path = "_devbuild/help/osh-option", .contents = gStr10},
1833 {.rel_path = "_devbuild/help/osh-osh-assign", .contents = gStr11},
1834 {.rel_path = "_devbuild/help/osh-plugin", .contents = gStr12},
1835 {.rel_path = "_devbuild/help/osh-special-var", .contents = gStr13},
1836 {.rel_path = "_devbuild/help/osh-stdlib", .contents = gStr14},
1837 {.rel_path = "_devbuild/help/osh-type-method", .contents = gStr15},
1838 {.rel_path = "_devbuild/help/osh-usage", .contents = gStr16},
1839 {.rel_path = "_devbuild/help/osh-word-lang", .contents = gStr17},
1840 {.rel_path = "_devbuild/help/ysh-builtin-cmd", .contents = gStr18},
1841 {.rel_path = "_devbuild/help/ysh-builtin-func", .contents = gStr19},
1842 {.rel_path = "_devbuild/help/ysh-chapters", .contents = gStr20},
1843 {.rel_path = "_devbuild/help/ysh-cmd-lang", .contents = gStr21},
1844 {.rel_path = "_devbuild/help/ysh-expr-lang", .contents = gStr22},
1845 {.rel_path = "_devbuild/help/ysh-front-end", .contents = gStr23},
1846 {.rel_path = "_devbuild/help/ysh-mini-lang", .contents = gStr24},
1847 {.rel_path = "_devbuild/help/ysh-option", .contents = gStr25},
1848 {.rel_path = "_devbuild/help/ysh-plugin", .contents = gStr26},
1849 {.rel_path = "_devbuild/help/ysh-special-var", .contents = gStr27},
1850 {.rel_path = "_devbuild/help/ysh-stdlib", .contents = gStr28},
1851 {.rel_path = "_devbuild/help/ysh-type-method", .contents = gStr29},
1852 {.rel_path = "_devbuild/help/ysh-usage", .contents = gStr30},
1853 {.rel_path = "_devbuild/help/ysh-word-lang", .contents = gStr31},
1854 {.rel_path = "_devbuild/help/ysh-ysh-cmd", .contents = gStr32},
1855 {.rel_path = "stdlib/funcs.ysh", .contents = gStr33},
1856 {.rel_path = "stdlib/methods.ysh", .contents = gStr34},
1857 {.rel_path = "stdlib/osh/bash-strict.sh", .contents = gStr35},
1858 {.rel_path = "stdlib/osh/byo-server.sh", .contents = gStr36},
1859 {.rel_path = "stdlib/osh/no-quotes.sh", .contents = gStr37},
1860 {.rel_path = "stdlib/osh/task-five.sh", .contents = gStr38},
1861 {.rel_path = "stdlib/osh/two.sh", .contents = gStr39},
1862 {.rel_path = "stdlib/prelude.ysh", .contents = gStr40},
1863 {.rel_path = "stdlib/testing.ysh", .contents = gStr41},
1864 {.rel_path = "stdlib/ysh/args.ysh", .contents = gStr42},
1865 {.rel_path = "stdlib/ysh/list.ysh", .contents = gStr43},
1866 {.rel_path = "stdlib/ysh/math.ysh", .contents = gStr44},
1867 {.rel_path = "stdlib/ysh/stream.ysh", .contents = gStr45},
1868 {.rel_path = "stdlib/ysh/table.ysh", .contents = gStr46},
1869 {.rel_path = "stdlib/ysh/yblocks.ysh", .contents = gStr47},
1870
1871 {.rel_path = nullptr, .contents = nullptr},
1872};
1873
1874} // namespace embedded_file
1875
1876TextFile* gEmbeddedFiles = embedded_file::array; // turn array into pointer