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

1866 lines, 158 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 # extdebug makes `declare -F` print the file path, but, annoyingly, only
628 # if you pass the function names as arguments.
629 shopt -s extdebug
630 declare -F "${funcs[@]}" | grep --fixed-strings " $0" | awk '{print $1}'
631 shopt -u extdebug
632}
633
634_gawk-print-funcs() {
635 ### Print shell functions in this file that don't start with _ (awk parsing)
636
637 # Using gawk because it has match()
638 # - doesn't start with _
639
640 # space = / ' '* /
641 # shfunc = / %begin
642 # <capture !['_' ' '] ![' ']*>
643 # '()' space '{' space
644 # %end /
645 # docstring = / %begin
646 # space '###' ' '+
647 # <capture dot*>
648 # %end /
649 gawk '
650 match($0, /^([^_ ][^ ]*)\(\)[ ]*{[ ]*$/, m) {
651 #print NR " shfunc " m[1]
652 print m[1]
653 #print m[0]
654 }
655
656 match($0, /^[ ]*###[ ]+(.*)$/, m) {
657 print NR " docstring " m[1]
658 }
659' $0
660}
661
662_print-funcs() {
663 _bash-print-funcs
664 return
665
666 # TODO: make gawk work, with docstrings
667 if command -v gawk > /dev/null; then
668 _gawk-print-funcs
669 else
670 _bash-print-funcs
671 fi
672}
673
674
675byo-maybe-run() {
676 local command=${BYO_COMMAND:-}
677
678 case $command in
679 '')
680 # Do nothing if it's not specified
681 return
682 ;;
683
684 detect)
685 # all the commands supported, except 'detect'
686 echo list-tests
687 echo run-test
688
689 exit 66 # ASCII code for 'B' - what the protocol specifies
690 ;;
691
692 list-tests)
693 # TODO: use _bash-print-funcs? This fixes the transitive test problem,
694 # which happened in soil/web-remote-test.sh
695 # But it should work with OSH, not just bash! We need shopt -s extdebug
696 compgen -A function | grep '^test-'
697 exit 0
698 ;;
699
700 run-test)
701 local test_name=${BYO_ARG:-}
702 if test -z "$test_name"; then
703 die "BYO run-test: Expected BYO_ARG"
704 fi
705
706 # Avoid issues polluting recursive calls!
707 unset BYO_COMMAND BYO_ARG
708
709 # Shell convention: we name functions test-*
710 "$test_name"
711
712 # Only run if not set -e. Either way it's equivalent
713 exit $?
714 ;;
715
716 *)
717 die "Invalid BYO command '$command'"
718 ;;
719 esac
720
721 # Do nothing if BYO_COMMAND is not set.
722 # The program continues to its "main".
723}
724
725byo-must-run() {
726 local command=${BYO_COMMAND:-}
727 if test -z "$command"; then
728 die "Expected BYO_COMMAND= in environment"
729 fi
730
731 byo-maybe-run
732}
733)zZXx");
734
735GLOBAL_STR(gStr37, R"zZXx(#!/usr/bin/env bash
736#
737# Testing library for bash and OSH.
738#
739# Capture status/stdout/stderr, and nq-assert those values.
740
741: ${LIB_OSH=stdlib/osh}
742source $LIB_OSH/two.sh
743
744nq-assert() {
745 ### Assertion with same syntax as shell 'test'
746
747 if ! test "$@"; then
748 die "line ${BASH_LINENO[0]}: nq-assert $(printf '%q ' "$@") failed"
749 fi
750}
751
752# Problem: we want to capture status and stdout at the same time
753#
754# We use:
755#
756# __stdout=$(set -o errexit; "$@")
757# __status=$?
758#
759# However, we lose the trailing \n, since that's how command subs work.
760
761# Here is another possibility:
762#
763# shopt -s lastpipe # need this too
764# ( set -o errexit; "$@" ) | read -r -d __stdout
765# __status=${PIPESTATUS[0]}
766# shopt -u lastpipe
767#
768# But this feels complex for just the \n issue, which can be easily worked
769# around.
770
771nq-run() {
772 ### capture status only
773
774 local -n out_status=$1
775 shift
776
777 local __status
778
779 # Tricky: turn errexit off so we can capture it, but turn it on against
780 set +o errexit
781 ( set -o errexit; "$@" )
782 __status=$?
783 set -o errexit
784
785 out_status=$__status
786}
787
788nq-capture() {
789 ### capture status and stdout
790
791 local -n out_status=$1
792 local -n out_stdout=$2
793 shift 2
794
795 local __status
796 local __stdout
797
798 # Tricky: turn errexit off so we can capture it, but turn it on against
799 set +o errexit
800 __stdout=$(set -o errexit; "$@")
801 __status=$?
802 set -o errexit
803
804 out_status=$__status
805 out_stdout=$__stdout
806}
807
808nq-capture-2() {
809 ### capture status and stderr
810
811 # This is almost identical to the above
812
813 local -n out_status=$1
814 local -n out_stderr=$2
815 shift 2
816
817 local __status
818 local __stderr
819
820 # Tricky: turn errexit off so we can capture it, but turn it on against
821 set +o errexit
822 __stderr=$(set -o errexit; "$@" 2>&1)
823 __status=$?
824 set -o errexit
825
826 out_status=$__status
827 out_stderr=$__stderr
828}
829
830# 'byo test' can set this?
831: ${NQ_TEST_TEMP=/tmp}
832
833nq-redir() {
834 ### capture status and stdout
835
836 local -n out_status=$1
837 local -n out_stdout_file=$2
838 shift 2
839
840 local __status
841 local __stdout_file=$NQ_TEST_TEMP/nq-redir-$$.txt
842
843 # Tricky: turn errexit off so we can capture it, but turn it on against
844 set +o errexit
845 ( set -o errexit; "$@" ) > $__stdout_file
846 __status=$?
847 set -o errexit
848
849 out_status=$__status
850 out_stdout_file=$__stdout_file
851}
852
853nq-redir-2() {
854 ### capture status and stdout
855
856 local -n out_status=$1
857 local -n out_stderr_file=$2
858 shift 2
859
860 local __status
861 local __stderr_file=$NQ_TEST_TEMP/nq-redir-$$.txt
862
863 # Tricky: turn errexit off so we can capture it, but turn it on against
864 set +o errexit
865 ( set -o errexit; "$@" ) 2> $__stderr_file
866 __status=$?
867 set -o errexit
868
869 out_status=$__status
870 out_stderr_file=$__stderr_file
871}
872)zZXx");
873
874GLOBAL_STR(gStr38, R"zZXx(#!/usr/bin/env bash
875#
876# Common shell functions for task scripts.
877#
878# Usage:
879# source $LIB_OSH/task-five.sh
880#
881# test-foo() { # define task functions
882# echo foo
883# }
884# task-five "$@"
885
886# Definition of a "task"
887#
888# - File invokes task-five "$@"
889# - or maybe you can look at its source
890# - It's a shell function
891# - Has ### docstring
892# - Doesn't start with _
893
894: ${LIB_OSH=stdlib/osh}
895source $LIB_OSH/byo-server.sh
896
897_show-help() {
898 # TODO:
899 # - Use awk to find comments at the top of the file?
900 # - Use OSH to extract docstrings
901 # - BYO_COMMAND=list-tasks will reuse that logic? It only applies to the
902 # current file, not anything in a different file?
903
904 echo "Usage: $0 TASK_NAME ARGS..."
905 echo
906 echo "To complete tasks, run:"
907 echo " source devtools/completion.bash"
908 echo
909 echo "Tasks:"
910
911 if command -v column >/dev/null; then
912 _print-funcs | column
913 else
914 _print-funcs
915 fi
916}
917
918task-five() {
919 # Respond to BYO_COMMAND=list-tasks, etc. All task files need this.
920 byo-maybe-run
921
922 case ${1:-} in
923 ''|--help|-h)
924 _show-help
925 exit 0
926 ;;
927 esac
928
929 if ! declare -f "$1" >/dev/null; then
930 echo "$0: '$1' isn't an action in this task file. Try '$0 --help'"
931 exit 1
932 fi
933
934 "$@"
935}
936)zZXx");
937
938GLOBAL_STR(gStr39, R"zZXx(# Two functions I actually use, all the time.
939#
940# To keep depenedencies small, this library will NEVER grow other functions
941# (and is named to imply that.)
942#
943# Usage:
944# source --builtin two.sh
945#
946# Examples:
947# log 'hi'
948# die 'expected a number'
949
950if command -v source-guard >/dev/null; then # include guard for YSH
951 source-guard two || return 0
952fi
953
954log() {
955 ### Write a message to stderr.
956 echo "$@" >&2
957}
958
959die() {
960 ### Write an error message with the script name, and exit with status 1.
961 log "$0: fatal: $@"
962 exit 1
963}
964
965)zZXx");
966
967GLOBAL_STR(gStr40, R"zZXx(# These were helpful while implementing args.ysh
968# Maybe we will want to export them in a prelude so that others can use them too?
969#
970# Prior art: Rust has `todo!()` which is quite nice. Other languages allow
971# users to `raise NotImplmentedError()`.
972
973# Andy comments:
974# - 'pass' can be : or true in shell. It's a little obscure / confusing, but
975# there is an argument for minimalism. Although I prefer words like 'true',
976# and that already means something.
977# - UPDATE: we once took 'pass' as a keyword, but users complained because
978# there is a command 'pass'. So we probably can't have this by default.
979# Need to discuss source --builtin.
980
981# - todo could be more static? Rust presumably does it at compile time
982
983proc todo () {
984 ## Raises a not implemented error when run.
985 error ("TODO: not implemented") # TODO: is error code 1 ok?
986}
987
988proc pass () {
989 ## Use when you want to temporarily leave a block empty.
990 _ null
991}
992)zZXx");
993
994GLOBAL_STR(gStr41, R"zZXx(# testing.ysh
995#
996# Usage:
997# source --builtin testing.sh
998#
999# func f(x) { return (x + 1) }
1000#
1001# describe foo {
1002# assert (43 === f(42))
1003# }
1004#
1005# if is-main {
1006# run-tests @ARGV # --filter
1007# }
1008
1009module stdlib/testing || return 0
1010
1011source --builtin args.ysh
1012
1013proc assert ( ; cond ; fail_message='default fail message') {
1014 echo 'hi from assert'
1015
1016 = cond
1017
1018 # I think this might be ready now?
1019
1020 var val = evalExpr(cond)
1021
1022 echo
1023 echo 'value'
1024 = val
1025 pp line (val)
1026
1027 = fail_message
1028
1029 if (val) {
1030 echo 'OK'
1031 } else {
1032 var m = evalExpr(fail_message)
1033 echo "FAIL - this is where we extract the string - $m"
1034 }
1035}
1036
1037proc test-assert {
1038 var x = 42
1039 assert [42 === x]
1040}
1041
1042proc test-expr ( ; expr ) {
1043 echo 'expr'
1044 pp line (expr)
1045}
1046
1047proc test-named ( ; ; n=^[99] ) {
1048 echo 'n'
1049 pp line (n)
1050}
1051
1052# What happens when there are duplicate test IDs?
1053#
1054# Also I think filter by "$test_id/$case_id"
1055
1056proc __it (case_id ; ; ; block) {
1057 # This uses a clean directory
1058 echo TODO
1059}
1060
1061# is this accessible to users?
1062# It can contain a global list of things to run
1063
1064# Naming convention: a proc named 'describe' mutates a global named _describe?
1065# Or maybe _describe_list ?
1066
1067var _describe_list = []
1068
1069proc describe (test_id ; ; ; block) {
1070 echo describe
1071 #= desc
1072
1073 # TODO:
1074 # - need append
1075 # - need ::
1076 # _ _describe->append(cmd)
1077 #
1078 # Need to clean this up
1079 # append (_describe, cmd) # does NOT work!
1080
1081 call _describe_list->append(block)
1082}
1083
1084proc Args {
1085 echo TODO
1086}
1087
1088# Problem: this creates a global variable?
1089Args (&spec) {
1090 flag --filter 'Regex of test descriptions'
1091}
1092
1093proc run-tests {
1094 var opt, i = parseArgs(spec, ARGV)
1095
1096 # TODO:
1097 # - parse --filter foo, which you can use eggex for!
1098
1099 for cmd in (_describe) {
1100 # TODO: print filename and 'describe' name?
1101 try {
1102 eval (cmd)
1103 }
1104 if (_status !== 0) {
1105 echo 'failed'
1106 }
1107 }
1108}
1109)zZXx");
1110
1111GLOBAL_STR(gStr42, R"zZXx(# args.ysh
1112#
1113# Usage:
1114# source --builtin args.sh
1115#
1116# parser (&spec) {
1117# flag -v --verbose (help="Verbosely") # default is Bool, false
1118#
1119# flag -P --max-procs ('int', default=-1, doc='''
1120# Run at most P processes at a time
1121# ''')
1122#
1123# flag -i --invert ('bool', default=true, doc='''
1124# Long multiline
1125# Description
1126# ''')
1127#
1128# arg src (help='Source')
1129# arg dest (help='Dest')
1130# arg times (help='Foo')
1131#
1132# rest files
1133# }
1134#
1135# var args = parseArgs(spec, ARGV)
1136#
1137# echo "Verbose $[args.verbose]"
1138
1139# TODO: See list
1140# - It would be nice to keep `flag` and `arg` private, injecting them into the
1141# proc namespace only within `Args`
1142# - We need "type object" to replace the strings 'int', 'bool', etc.
1143# - flag builtin:
1144# - handle only long flag or only short flag
1145# - flag aliases
1146
1147proc parser (; place ; ; block_def) {
1148 ## Create an args spec which can be passed to parseArgs.
1149 ##
1150 ## Example:
1151 ##
1152 ## # NOTE: &spec will create a variable named spec
1153 ## parser (&spec) {
1154 ## flag -v --verbose ('bool')
1155 ## }
1156 ##
1157 ## var args = parseArgs(spec, ARGV)
1158
1159 var p = {flags: [], args: []}
1160 ctx push (p; ; block_def)
1161
1162 # Validate that p.rest = [name] or null and reduce p.rest into name or null.
1163 if ('rest' in p) {
1164 if (len(p.rest) > 1) {
1165 error '`rest` was called more than once' (code=3)
1166 } else {
1167 setvar p.rest = p.rest[0]
1168 }
1169 } else {
1170 setvar p.rest = null
1171 }
1172
1173 var names = {}
1174 for items in ([p.flags, p.args]) {
1175 for x in (items) {
1176 if (x.name in names) {
1177 error "Duplicate flag/arg name $[x.name] in spec" (code=3)
1178 }
1179
1180 setvar names[x.name] = null
1181 }
1182 }
1183
1184 # TODO: what about `flag --name` and then `arg name`?
1185
1186 call place->setValue(p)
1187}
1188
1189proc flag (short, long ; type='bool' ; default=null, help=null) {
1190 ## Declare a flag within an `arg-parse`.
1191 ##
1192 ## Examples:
1193 ##
1194 ## arg-parse (&spec) {
1195 ## flag -v --verbose
1196 ## flag -n --count ('int', default=1)
1197 ## flag -f --file ('str', help="File to process")
1198 ## }
1199
1200 # bool has a default of false, not null
1201 if (type === 'bool' and default === null) {
1202 setvar default = false
1203 }
1204
1205 # TODO: validate `type`
1206
1207 # TODO: Should use "trimPrefix"
1208 var name = long[2:]
1209
1210 ctx emit flags ({short, long, name, type, default, help})
1211}
1212
1213proc arg (name ; ; help=null) {
1214 ## Declare a positional argument within an `arg-parse`.
1215 ##
1216 ## Examples:
1217 ##
1218 ## arg-parse (&spec) {
1219 ## arg name
1220 ## arg config (help="config file path")
1221 ## }
1222
1223 ctx emit args ({name, help})
1224}
1225
1226proc rest (name) {
1227 ## Take the remaining positional arguments within an `arg-parse`.
1228 ##
1229 ## Examples:
1230 ##
1231 ## arg-parse (&grepSpec) {
1232 ## arg query
1233 ## rest files
1234 ## }
1235
1236 # We emit instead of set to detect multiple invocations of "rest"
1237 ctx emit rest (name)
1238}
1239
1240func parseArgs(spec, argv) {
1241 ## Given a spec created by `parser`. Parse an array of strings `argv` per
1242 ## that spec.
1243 ##
1244 ## See `parser` for examples of use.
1245
1246 var i = 0
1247 var positionalPos = 0
1248 var argc = len(argv)
1249 var args = {}
1250 var rest = []
1251
1252 var value
1253 var found
1254 while (i < argc) {
1255 var arg = argv[i]
1256 if (arg->startsWith('-')) {
1257 setvar found = false
1258
1259 for flag in (spec.flags) {
1260 if ( (flag.short and flag.short === arg) or
1261 (flag.long and flag.long === arg) ) {
1262 case (flag.type) {
1263 ('bool') | (null) { setvar value = true }
1264 int {
1265 setvar i += 1
1266 if (i >= len(argv)) {
1267 error "Expected integer after '$arg'" (code=2)
1268 }
1269
1270 try { setvar value = int(argv[i]) }
1271 if (_status !== 0) {
1272 error "Expected integer after '$arg', got '$[argv[i]]'" (code=2)
1273 }
1274 }
1275 }
1276
1277 setvar args[flag.name] = value
1278 setvar found = true
1279 break
1280 }
1281 }
1282
1283 if (not found) {
1284 error "Unknown flag '$arg'" (code=2)
1285 }
1286 } elif (positionalPos >= len(spec.args)) {
1287 if (not spec.rest) {
1288 error "Too many arguments, unexpected '$arg'" (code=2)
1289 }
1290
1291 call rest->append(arg)
1292 } else {
1293 var pos = spec.args[positionalPos]
1294 setvar positionalPos += 1
1295 setvar value = arg
1296 setvar args[pos.name] = value
1297 }
1298
1299 setvar i += 1
1300 }
1301
1302 if (spec.rest) {
1303 setvar args[spec.rest] = rest
1304 }
1305
1306 # Set defaults for flags
1307 for flag in (spec.flags) {
1308 if (flag.name not in args) {
1309 setvar args[flag.name] = flag.default
1310 }
1311 }
1312
1313 # Raise error on missing args
1314 for arg in (spec.args) {
1315 if (arg.name not in args) {
1316 error "Usage Error: Missing required argument $[arg.name]" (code=2)
1317 }
1318 }
1319
1320 return (args)
1321}
1322)zZXx");
1323
1324GLOBAL_STR(gStr43, R"zZXx(func any(list) {
1325 ### Returns true if any value in the list is truthy.
1326 # Empty list: returns false
1327
1328 for item in (list) {
1329 if (item) {
1330 return (true)
1331 }
1332 }
1333 return (false)
1334}
1335
1336func all(list) {
1337 ## Returns true if all values in the list are truthy.
1338 # Empty list: returns true
1339
1340 for item in (list) {
1341 if (not item) {
1342 return (false)
1343 }
1344 }
1345 return (true)
1346}
1347
1348func sum(list; start=0) {
1349 ### Returns the sum of all elements in the list.
1350 # Empty list: returns 0
1351
1352 var sum = start
1353 for item in (list) {
1354 setvar sum += item
1355 }
1356 return (sum)
1357}
1358
1359func repeat(x, n) {
1360 ### Returns a list with the given string or list repeated
1361
1362 # Like Python's 'foo'*3 or ['foo', 'bar']*3
1363 # negative numbers are like 0 in Python
1364
1365 var t = type(x)
1366 case (t) {
1367 Str {
1368 var parts = []
1369 for i in (0 .. n) {
1370 call parts->append(x)
1371 }
1372 return (join(parts))
1373 }
1374 List {
1375 var result = []
1376 for i in (0 .. n) {
1377 call result->extend(x)
1378 }
1379 return (result)
1380 }
1381 (else) {
1382 error "Expected Str or List, got $t"
1383 }
1384 }
1385}
1386)zZXx");
1387
1388GLOBAL_STR(gStr44, R"zZXx(func __math_select(list, cmp) {
1389 ## Internal helper for `max` and `min`.
1390 ##
1391 ## NOTE: If `list` is empty, then an error is thrown.
1392
1393 if (len(list) === 0) {
1394 error "Unexpected empty list" (code=3)
1395 }
1396
1397 if (len(list) === 1) {
1398 return (list[0])
1399 }
1400
1401 var match = list[0]
1402 for i in (1 .. len(list)) {
1403 setvar match = cmp(list[i], match)
1404 }
1405 return (match)
1406}
1407
1408func max(...args) {
1409 ## Compute the maximum of 2 or more values.
1410 ##
1411 ## `max` takes two different signatures:
1412 ## - `max(a, b)` to return the maximum of `a`, `b`
1413 ## - `max(list)` to return the greatest item in the `list`
1414 ##
1415 ## So, for example:
1416 ##
1417 ## max(1, 2) # => 2
1418 ## max([1, 2, 3]) # => 3
1419
1420 case (len(args)) {
1421 (1) { return (__math_select(args[0], max)) }
1422 (2) {
1423 if (args[0] > args[1]) {
1424 return (args[0])
1425 } else {
1426 return (args[1])
1427 }
1428 }
1429 (else) { error "max expects 1 or 2 args" (code=3) }
1430 }
1431}
1432
1433func min(...args) {
1434 ## Compute the minimum of 2 or more values.
1435 ##
1436 ## `min` takes two different signatures:
1437 ## - `min(a, b)` to return the minimum of `a`, `b`
1438 ## - `min(list)` to return the least item in the `list`
1439 ##
1440 ## So, for example:
1441 ##
1442 ## min(2, 3) # => 2
1443 ## max([1, 2, 3]) # => 1
1444
1445 case (len(args)) {
1446 (1) { return (__math_select(args[0], min)) }
1447 (2) {
1448 if (args[0] < args[1]) {
1449 return (args[0])
1450 } else {
1451 return (args[1])
1452 }
1453 }
1454 (else) { error "min expects 1 or 2 args" (code=3) }
1455 }
1456}
1457
1458func abs(x) {
1459 ## Compute the absolute (positive) value of a number (float or int).
1460
1461 if (x < 0) {
1462 return (-x)
1463 } else {
1464 return (x)
1465 }
1466}
1467)zZXx");
1468
1469GLOBAL_STR(gStr45, R"zZXx(# stream.ysh
1470#
1471# Usage:
1472# source --builtin stream.ysh
1473#
1474# For reading lines, decoding, extracting, splitting
1475
1476# make this file a test server
1477source $LIB_OSH/byo-server.sh
1478
1479source $LIB_YSH/args.ysh
1480
1481proc slurp-by (; num_lines) {
1482 # TODO: (stdin)
1483 for line in (stdin) {
1484 echo TODO
1485 }
1486}
1487
1488# Note:
1489# - these are all the same algorithm
1490# - also word, block, etc. are all optional
1491
1492proc each-line (...words; template=null; ; block=null) {
1493 # TODO:
1494 # parse --j8 --max-jobs flag
1495
1496 # parse template_str as string
1497 # TODO: this is dangerous though ... because you can execute code
1498 # I think you need a SAFE version
1499
1500 # evaluate template string expression - I guess that allows $(echo hi) and so
1501 # forth
1502
1503 # evaluate block with _line binding
1504 # block: execute in parallel with --max-jobs
1505
1506 for line in (stdin) {
1507 echo TODO
1508 }
1509}
1510
1511proc test-each-line {
1512 echo 'TODO: need basic test runner'
1513
1514 # ysh-tool test stream.ysh
1515 #
1516 # Col
1517
1518
1519}
1520
1521proc each-row (; ; block) {
1522 echo TODO
1523}
1524
1525proc split-by (; ifs=null; block) {
1526 echo TODO
1527}
1528
1529proc if-split-by (; ifs=null; block) {
1530 echo TODO
1531}
1532
1533proc chop () {
1534 ### alias for if-split-by
1535 echo TODO
1536}
1537
1538proc must-match (; pattern; block) {
1539 echo TODO
1540}
1541
1542proc if-match (; pattern; block) {
1543 echo TODO
1544}
1545
1546# Protocol:
1547#
1548# - The file lists its tests the "actions"
1549# - Then the test harness runs them
1550# - But should it be ENV vars
1551#
1552# - BYO_LIST_TESTS=1
1553# - BYO_RUN_TEST=foo
1554# - $PWD is a CLEAN temp dir, the process doesn't have to do anything
1555
1556# - silent on success, but prints file on output
1557# - OK this makes sense
1558#
1559# The trivial test in Python:
1560#
1561# from test import byo
1562# byo.maybe_main()
1563#
1564# bash library:
1565# source --builtin byo-server.sh
1566#
1567# byo-maybe-main # reads env variables, and then exits
1568#
1569# source --builtin assertions.ysh
1570#
1571# assert-ok 'echo hi'
1572# assert-stdout 'hi' 'echo -n hi'
1573#
1574# "$@"
1575#
1576# Run all tests
1577# util/byo-client.sh run-tests $YSH stdlib/table.ysh
1578# util/byo-client.sh run-tests -f x $YSH stdlib/table.ysh
1579
1580# Clean process
1581# Clean working dir
1582
1583#
1584# Stream Protocol:
1585# #.byo - is this she-dot, that's for a file
1586# Do we need metadata?
1587#
1588
1589# The harness
1590#
1591# It's process based testing.
1592#
1593# Test runner process: bash or OSH (unlike sharness!)
1594# Tested process: any language - bash,
1595#
1596# Key point: you don't have to quote shell code?
1597
1598list-byo-tests() {
1599 echo TODO
1600}
1601
1602run-byo-tests() {
1603 # source it
1604 echo TODO
1605}
1606
1607byo-maybe-run
1608)zZXx");
1609
1610GLOBAL_STR(gStr46, R"zZXx(# table.ysh - Library for tables.
1611#
1612# Usage:
1613# source --builtin table.ysh
1614
1615# make this file a test server
1616source --builtin osh/byo-server.sh
1617
1618proc table (...words; place; ; block) {
1619 var n = len(words)
1620
1621 # TODO: parse flags
1622 #
1623 # --by-row
1624 # --by-col
1625 #
1626 # Place is optional
1627
1628 if (n === 0) {
1629 echo TODO
1630 return
1631 }
1632
1633 var action = words[0]
1634
1635 # textual operations
1636 case (action) {
1637 cat {
1638 echo todo
1639 }
1640 align {
1641 echo todo
1642 }
1643 tabify {
1644 echo todo
1645 }
1646 tabify {
1647 echo todo
1648 }
1649 header {
1650 echo todo
1651 }
1652 slice {
1653 # this has typed args
1654 # do we do some sort of splat?
1655 echo todo
1656 }
1657 to-tsv {
1658 echo todo
1659 }
1660 }
1661
1662 echo TODO
1663}
1664
1665proc test-table {
1666 return
1667
1668 table (&files1) {
1669 cols num_bytes path
1670 type Int Str
1671
1672 row 10 README.md
1673 row 12 main.py
1674
1675 row (12, 'lib.py')
1676 row (num_bytes=12, path='util.py')
1677 }
1678
1679 # 2 columns - The default is by column?
1680 assert ['Dict' === type(files1)]
1681 assert [2 === len(files1)]
1682
1683 # Same table
1684 table --by-row (&files2) {
1685 cols num_bytes path
1686 type Int Str
1687
1688 row 10 README.md
1689 row 12 main.py
1690
1691 row (12, 'lib.py')
1692 row (num_bytes=12, path='util.py')
1693 }
1694
1695 # 4 rows
1696 assert ['List' === type(files2)]
1697 assert [4 === len(files2)]
1698}
1699
1700# "subcommands" of the dialect
1701
1702proc cols (...names) {
1703 # cols name age
1704 echo TODO
1705}
1706
1707proc types (...types) {
1708 # types - Int? Str?
1709 echo TODO
1710}
1711
1712proc attr (name; ...values) {
1713 # attr units ('-', 'secs')
1714 echo TODO
1715}
1716
1717# is this allowed outside table {} blocks too?
1718proc row {
1719 echo TODO
1720}
1721
1722#
1723# dplyr names
1724#
1725
1726# TODO: can we parse select?
1727
1728proc where {
1729 echo
1730}
1731
1732# TODO: should be able to test argv[0] or something
1733# Or pass to _mutate-transmute
1734
1735proc mutate {
1736 echo TODO
1737}
1738
1739proc transmute {
1740 echo TODO
1741}
1742
1743proc rename {
1744 echo TODO
1745}
1746
1747proc group-by {
1748 echo TODO
1749}
1750
1751proc sort-by {
1752 echo TODO
1753}
1754
1755proc summary {
1756 echo TODO
1757}
1758
1759byo-maybe-run
1760)zZXx");
1761
1762GLOBAL_STR(gStr47, R"zZXx(#!/usr/bin/env bash
1763#
1764# Testing library for bash and OSH.
1765#
1766# Capture status/stdout/stderr, and nq-assert those values.
1767
1768#module yblocks || return 0
1769
1770: ${LIB_OSH=stdlib/osh}
1771source $LIB_OSH/two.sh
1772
1773# There is no yb-run, because you can just use try { } and inspect _error.code
1774# There is no yb-redir, because you can just use try >$tmp { } and inspect _error.code
1775
1776proc yb-capture(; out; ; block) {
1777 ### capture status and stderr
1778
1779 var stdout = ''
1780 try {
1781 eval (block) | read --all (&stdout)
1782 }
1783 # TODO: if 'block' contains a pipeline, we lose this magic var
1784 var result = {status: _pipeline_status[0], stdout}
1785
1786 #echo 'result-1'
1787 #pp test_ (result)
1788
1789 call out->setValue(result)
1790}
1791
1792proc yb-capture-2(; out; ; block) {
1793 ### capture status and stderr
1794
1795 var stderr = ''
1796 try {
1797 eval (block) 2>&1 | read --all (&stderr)
1798 }
1799 #pp test_ (_pipeline_status)
1800
1801 var result = {status: _pipeline_status[0], stderr}
1802 #echo 'result-2'
1803 #pp test_ (result)
1804
1805 call out->setValue(result)
1806}
1807)zZXx");
1808
1809
1810
1811TextFile array[] = {
1812 {.rel_path = "_devbuild/help/data-errors", .contents = gStr0},
1813 {.rel_path = "_devbuild/help/data-front-end", .contents = gStr1},
1814 {.rel_path = "_devbuild/help/data-j8-notation", .contents = gStr2},
1815 {.rel_path = "_devbuild/help/help", .contents = gStr3},
1816 {.rel_path = "_devbuild/help/oils-usage", .contents = gStr4},
1817 {.rel_path = "_devbuild/help/osh-builtin-cmd", .contents = gStr5},
1818 {.rel_path = "_devbuild/help/osh-chapters", .contents = gStr6},
1819 {.rel_path = "_devbuild/help/osh-cmd-lang", .contents = gStr7},
1820 {.rel_path = "_devbuild/help/osh-front-end", .contents = gStr8},
1821 {.rel_path = "_devbuild/help/osh-mini-lang", .contents = gStr9},
1822 {.rel_path = "_devbuild/help/osh-option", .contents = gStr10},
1823 {.rel_path = "_devbuild/help/osh-osh-assign", .contents = gStr11},
1824 {.rel_path = "_devbuild/help/osh-plugin", .contents = gStr12},
1825 {.rel_path = "_devbuild/help/osh-special-var", .contents = gStr13},
1826 {.rel_path = "_devbuild/help/osh-stdlib", .contents = gStr14},
1827 {.rel_path = "_devbuild/help/osh-type-method", .contents = gStr15},
1828 {.rel_path = "_devbuild/help/osh-usage", .contents = gStr16},
1829 {.rel_path = "_devbuild/help/osh-word-lang", .contents = gStr17},
1830 {.rel_path = "_devbuild/help/ysh-builtin-cmd", .contents = gStr18},
1831 {.rel_path = "_devbuild/help/ysh-builtin-func", .contents = gStr19},
1832 {.rel_path = "_devbuild/help/ysh-chapters", .contents = gStr20},
1833 {.rel_path = "_devbuild/help/ysh-cmd-lang", .contents = gStr21},
1834 {.rel_path = "_devbuild/help/ysh-expr-lang", .contents = gStr22},
1835 {.rel_path = "_devbuild/help/ysh-front-end", .contents = gStr23},
1836 {.rel_path = "_devbuild/help/ysh-mini-lang", .contents = gStr24},
1837 {.rel_path = "_devbuild/help/ysh-option", .contents = gStr25},
1838 {.rel_path = "_devbuild/help/ysh-plugin", .contents = gStr26},
1839 {.rel_path = "_devbuild/help/ysh-special-var", .contents = gStr27},
1840 {.rel_path = "_devbuild/help/ysh-stdlib", .contents = gStr28},
1841 {.rel_path = "_devbuild/help/ysh-type-method", .contents = gStr29},
1842 {.rel_path = "_devbuild/help/ysh-usage", .contents = gStr30},
1843 {.rel_path = "_devbuild/help/ysh-word-lang", .contents = gStr31},
1844 {.rel_path = "_devbuild/help/ysh-ysh-cmd", .contents = gStr32},
1845 {.rel_path = "stdlib/funcs.ysh", .contents = gStr33},
1846 {.rel_path = "stdlib/methods.ysh", .contents = gStr34},
1847 {.rel_path = "stdlib/osh/bash-strict.sh", .contents = gStr35},
1848 {.rel_path = "stdlib/osh/byo-server.sh", .contents = gStr36},
1849 {.rel_path = "stdlib/osh/no-quotes.sh", .contents = gStr37},
1850 {.rel_path = "stdlib/osh/task-five.sh", .contents = gStr38},
1851 {.rel_path = "stdlib/osh/two.sh", .contents = gStr39},
1852 {.rel_path = "stdlib/prelude.ysh", .contents = gStr40},
1853 {.rel_path = "stdlib/testing.ysh", .contents = gStr41},
1854 {.rel_path = "stdlib/ysh/args.ysh", .contents = gStr42},
1855 {.rel_path = "stdlib/ysh/list.ysh", .contents = gStr43},
1856 {.rel_path = "stdlib/ysh/math.ysh", .contents = gStr44},
1857 {.rel_path = "stdlib/ysh/stream.ysh", .contents = gStr45},
1858 {.rel_path = "stdlib/ysh/table.ysh", .contents = gStr46},
1859 {.rel_path = "stdlib/ysh/yblocks.ysh", .contents = gStr47},
1860
1861 {.rel_path = nullptr, .contents = nullptr},
1862};
1863
1864} // namespace embedded_file
1865
1866TextFile* gEmbeddedFiles = embedded_file::array; // turn array into pointer