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

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