OILS / stdlib / table.ysh View on Github | oilshell.org

148 lines, 89 significant
1# table.ysh - Library for tables.
2#
3# Usage:
4# source --builtin table.ysh
5
6# make this file a test server
7source --builtin byo-server-lib.sh
8
9proc table (...words; place; ; block) {
10 var n = len(words)
11
12 # TODO: parse flags
13 #
14 # --by-row
15 # --by-col
16 #
17 # Place is optional
18
19 if (n === 0) {
20 echo TODO
21 return
22 }
23
24 var action = words[0]
25
26 # textual operations
27 case (action) {
28 cat {
29 echo todo
30 }
31 align {
32 echo todo
33 }
34 tabify {
35 echo todo
36 }
37 tabify {
38 echo todo
39 }
40 header {
41 echo todo
42 }
43 slice {
44 # this has typed args
45 # do we do some sort of splat?
46 echo todo
47 }
48 to-tsv {
49 echo todo
50 }
51 }
52
53 echo TODO
54}
55
56proc test-table {
57 table (&files1) {
58 cols num_bytes path
59 type Int Str
60
61 row 10 README.md
62 row 12 main.py
63
64 row (12, 'lib.py')
65 row (num_bytes=12, path='util.py')
66 }
67
68 # 2 columns - The default is by column?
69 assert ['Dict' === type(files1)]
70 assert [2 === len(files1)]
71
72 # Same table
73 table --by-row (&files2) {
74 cols num_bytes path
75 type Int Str
76
77 row 10 README.md
78 row 12 main.py
79
80 row (12, 'lib.py')
81 row (num_bytes=12, path='util.py')
82 }
83
84 # 4 rows
85 assert ['List' === type(files2)]
86 assert [4 === len(files2)]
87}
88
89# "subcommands" of the dialect
90
91proc cols (...names) {
92 # cols name age
93 echo TODO
94}
95
96proc types (...types) {
97 # types - Int? Str?
98 echo TODO
99}
100
101proc attr (name; ...values) {
102 # attr units ('-', 'secs')
103 echo TODO
104}
105
106# is this allowed outside table {} blocks too?
107proc row {
108 echo TODO
109}
110
111#
112# dplyr names
113#
114
115# TODO: can we parse select?
116
117proc where {
118 echo
119}
120
121# TODO: should be able to test argv[0] or something
122# Or pass to _mutate-transmute
123
124proc mutate {
125 echo TODO
126}
127
128proc transmute {
129 echo TODO
130}
131
132proc rename {
133 echo TODO
134}
135
136proc group-by {
137 echo TODO
138}
139
140proc sort-by {
141 echo TODO
142}
143
144proc summary {
145 echo TODO
146}
147
148byo-maybe-main