11# ## Convert yaml to json
22
3- [[alias ]]
3+ [[command ]]
44
55name = " yml2json"
66short_help = " Convert yaml to json"
77
8- [[alias .stage ]]
8+ [[command .stage ]]
99command = " stack"
1010options = {code =" yaml.safe_load ! json.dumps" }
1111
12- [[alias .test ]]
12+ [[command .test ]]
1313invocation = [" yml2json" ]
1414input = ''' {"x": 1,}
1515'''
@@ -19,22 +19,25 @@ output = '''{"x": 1}
1919
2020# ## Search for xpath elements with xpath
2121
22- [[alias ]]
22+ [[command ]]
2323name =" xpath"
2424short_help = " Find xml elements matching xpath query."
2525arguments = [{name =" query" , type =" str" }]
2626inject_values =[" query" ]
2727
28- [[alias .stage ]]
28+
29+ help = """ Pull data out of xml documents using xpath."""
30+
31+ [[command .stage ]]
2932
3033command = " stack"
3134options = {code =" x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
3235
33- [[alias .stage ]]
36+ [[command .stage ]]
3437command =" chain"
3538
3639
37- [[alias .test ]]
40+ [[command .test ]]
3841invocation = [" xpath" , " //" , " map" , " x.text" ]
3942input = '''
4043<slide type="all">
@@ -51,132 +54,132 @@ Anything in here
5154
5255# ## Generate json objects
5356
54- [[alias ]]
57+ [[command ]]
5558name =" jo"
5659short_help =" Make json objects"
5760arguments =[{name =" pairs" , type =" str" }]
5861inject_values =[" pairs" ]
5962
6063
61- [[alias .stage ]]
64+ [[command .stage ]]
6265command = " eval"
6366options = {code =" pairs" }
6467
65- [[alias .stage ]]
68+ [[command .stage ]]
6669command = " map"
6770options = {code =" shlex.split(x, posix=False)" }
6871
69- [[alias .stage ]]
72+ [[command .stage ]]
7073command = " chain"
7174
72- [[alias .stage ]]
75+ [[command .stage ]]
7376command = " map"
7477options = {code =" x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\ g<value>\" ', x[2]))]" }
7578
76- [[alias .stage ]]
79+ [[command .stage ]]
7780command = " apply"
7881options = {"code" =" dict" }
7982
80- [[alias .stage ]]
83+ [[command .stage ]]
8184command = " map"
8285options = {code =" json.dumps" }
8386
8487
85- [[alias .test ]]
88+ [[command .test ]]
8689invocation = [" jo" , " x=1 y=2" ]
8790input = " "
8891output = " {\" x\" : 1, \" y\" : 2}\n "
8992
9093
91- [[alias ]]
94+ [[command ]]
9295name = " read-jsonl"
9396short_help = " Load jsonlines into python objects"
9497section =" Read"
9598
96- [[alias .stage ]]
99+ [[command .stage ]]
97100
98101command = " map"
99102
100103options = {code =" json.loads" }
101104
102- [[alias .test ]]
105+ [[command .test ]]
103106invocation = [" read-jsonl" ]
104107input = """ {"name": "Alice", "age": "21"}\n {"name": "Bob", "age": "22"}\n """
105108output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
106109
107110
108- [[alias ]]
111+ [[command ]]
109112name = " read-csv"
110113short_help = " Load csv rows into python objects"
111114inject_values =[" delimiter" , " header" ]
112115section =" Read"
113116
114- [[alias .options ]]
117+ [[command .options ]]
115118name = " --delimiter"
116119default = " ,"
117- help = " field delimiter character"
120+ help = " Field delimiter character"
118121
119- [[alias .options ]]
122+ [[command .options ]]
120123name = " --header/--no-header"
121124default =true
122125help = " Treat the first row as a header?"
123126
124- [[alias .stage ]]
127+ [[command .stage ]]
125128command = " apply"
126129options = {code =" mario_addons.plugins.addons.read_csv(x, header=header)" }
127130
128- [[alias .stage ]]
131+ [[command .stage ]]
129132command = " chain"
130133
131- [[alias .stage ]]
134+ [[command .stage ]]
132135command = " map"
133136options = {code =" dict(x)" }
134137
135- [[alias .test ]]
138+ [[command .test ]]
136139invocation = [" read-csv" ]
137140input = """ name,age\n Alice,21\n Bob,22\n """
138141output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
139142
140143
141- [[alias ]]
144+ [[command ]]
142145name = " read-yaml"
143146short_help = " Read yaml document"
144147section = " Read"
145148
146- [[alias .stage ]]
149+ [[command .stage ]]
147150command = " stack"
148151options = {code =" yaml.safe_load" }
149152
150- [[alias .test ]]
153+ [[command .test ]]
151154invocation = [" read-yaml" ]
152155input = " {'x': 1,}\n "
153156output = " {'x': 1}\n "
154157
155- [[alias ]]
158+ [[command ]]
156159name = ' write-json'
157160short_help = " Write json document"
158161section = " Write"
159162
160- [[alias .stage ]]
163+ [[command .stage ]]
161164command = " apply"
162165options ={code =" json.dumps" }
163166
164- [[alias .test ]]
167+ [[command .test ]]
165168invocation = [" stack" , " str.split" , " write-json" ]
166169input = " 1 2\n "
167170output =" [[\" 1\" , \" 2\" ]]\n "
168171
169172
170- [[alias ]]
173+ [[command ]]
171174name = ' write-toml'
172175short_help = " Write toml document"
173176section = " Write"
174177
175- [[alias .stage ]]
178+ [[command .stage ]]
176179command = " map"
177180options ={code =" toml.dumps" }
178181
179- [[alias .test ]]
182+ [[command .test ]]
180183invocation = [" stack" , " json.loads" , " write-toml" ]
181184input = ''' {"x": 1}
182185'''
0 commit comments