11# ## Convert yaml to json
22
3- [[alias ]]
3+ [[command ]]
44
5- name = " yml2json"
6- help = " Convert yaml to json"
5+ name = " yml2json"
6+ short_help = " Convert yaml to json"
77
8- [[ alias .stage ]]
9- command = " stack"
10- options = {code =" yaml.safe_load ! json.dumps" }
8+ [[ command .stage ]]
9+ command = " stack"
10+ options = {code =" yaml.safe_load ! json.dumps" }
1111
12- [[ alias .test ]]
13- invocation = [" yml2json" ]
14- input = ''' {"x": 1,}
12+ [[ command .test ]]
13+ invocation = [" yml2json" ]
14+ input = ''' {"x": 1,}
1515'''
16- output = ''' {"x": 1}
16+ output = ''' {"x": 1}
1717'''
1818
1919
2020# ## Search for xpath elements with xpath
2121
22- [[alias ]]
23- name =" xpath"
24- help = " Find xml elements matching xpath query."
25- arguments = [{name =" query" , type =" str" }]
26- inject_values =[" query" ]
22+ [[command ]]
23+ name =" xpath"
24+ short_help = " Find xml elements matching xpath query."
25+ arguments = [{name =" query" , type =" str" }]
26+ inject_values =[" query" ]
2727
28- [[alias .stage ]]
2928
30- command = " stack"
31- options = {code =" x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
29+ help = """ Pull data out of xml documents using xpath."""
3230
33- [[alias .stage ]]
34- command =" chain"
31+ [[command .stage ]]
3532
33+ command = " stack"
34+ options = {code =" x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
3635
37- [[alias .test ]]
38- invocation = [" xpath" , " //" , " map" , " x.text" ]
39- input = """
40- <slide type="all">
41- <title>Overview</title>
42- <item>Anything in here</item>
43- </slide>
44- """
45- output = """
36+ [[command .stage ]]
37+ command =" chain"
38+
39+
40+ [[command .test ]]
41+ invocation = [" xpath" , " //" , " map" , " x.text" ]
42+ input = '''
43+ <slide type="all">
44+ <title>Overview</title>
45+ <item>Anything in here</item>
46+ </slide>
47+ '''
48+ output = """
4649Overview
4750Anything in here
4851"""
@@ -51,137 +54,132 @@ Anything in here
5154
5255# ## Generate json objects
5356
54- [[alias ]]
55-
56-
57- name =" jo"
58- help =" Make json objects"
59- arguments =[{name =" pairs" , type =" str" }]
60- inject_values =[" pairs" ]
61-
57+ [[command ]]
58+ name =" jo"
59+ short_help =" Make json objects"
60+ arguments =[{name =" pairs" , type =" str" }]
61+ inject_values =[" pairs" ]
6262
63- [[alias .stage ]]
64- command = " eval"
65- options = {code =" pairs" }
6663
67- [[ alias .stage ]]
68- command = " map "
69- options = {code =" shlex.split(x, posix=False) " }
64+ [[ command .stage ]]
65+ command = " eval "
66+ options = {code =" pairs " }
7067
71- [[alias .stage ]]
72- command = " chain"
68+ [[command .stage ]]
69+ command = " map"
70+ options = {code =" shlex.split(x, posix=False)" }
7371
74- [[alias .stage ]]
75- command = " map"
76- options = {code =" x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\ g<value>\" ', x[2]))]" }
72+ [[command .stage ]]
73+ command = " chain"
7774
78- [[ alias .stage ]]
79- command = " apply "
80- options = {" code" = " dict " }
75+ [[ command .stage ]]
76+ command = " map "
77+ options = {code = " x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r' \"\\ g<value> \" ', x[2]))] " }
8178
82- [[ alias .stage ]]
83- command = " map "
84- options = {code = " json.dumps " }
79+ [[ command .stage ]]
80+ command = " apply "
81+ options = {" code" = " dict " }
8582
83+ [[command .stage ]]
84+ command = " map"
85+ options = {code =" json.dumps" }
8686
87- [[alias .test ]]
88- invocation = [" jo" , " x=1 y=2" ]
89- input = " "
90- output = " {\" x\" : 1, \" y\" : 2}\n "
9187
88+ [[command .test ]]
89+ invocation = [" jo" , " x=1 y=2" ]
90+ input = " "
91+ output = " {\" x\" : 1, \" y\" : 2}\n "
9292
93- [[alias ]]
9493
95- name = " read-jsonl"
96- help = " Load jsonlines into python objects"
97- section =" Read"
94+ [[command ]]
95+ name = " read-jsonl"
96+ short_help = " Load jsonlines into python objects"
97+ section =" Read"
9898
99- [[ alias .stage ]]
99+ [[ command .stage ]]
100100
101- command = " map"
101+ command = " map"
102102
103- options = {code =" json.loads" }
103+ options = {code =" json.loads" }
104104
105- [[ alias .test ]]
106- invocation = [" read-jsonl" ]
107- input = """ {"name": "Alice", "age": "21"}\n {"name": "Bob", "age": "22"}\n """
108- output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
105+ [[ command .test ]]
106+ invocation = [" read-jsonl" ]
107+ input = """ {"name": "Alice", "age": "21"}\n {"name": "Bob", "age": "22"}\n """
108+ output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
109109
110110
111- [[alias ]]
112- name = " read-csv"
113- help = " Load csv rows into python objects"
114- inject_values =[" delimiter" , " header" ]
115- section =" Read"
111+ [[command ]]
112+ name = " read-csv"
113+ short_help = " Load csv rows into python objects"
114+ inject_values =[" delimiter" , " header" ]
115+ section =" Read"
116116
117- [[ alias .options ]]
118- name = " --delimiter"
119- default = " ,"
120- help = " field delimiter character"
117+ [[ command .options ]]
118+ name = " --delimiter"
119+ default = " ,"
120+ help = " Field delimiter character"
121121
122- [[ alias .options ]]
123- name = " --header/--no-header"
124- default =true
125- help = " Treat the first row as a header?"
122+ [[ command .options ]]
123+ name = " --header/--no-header"
124+ default =true
125+ help = " Treat the first row as a header?"
126126
127- [[ alias .stage ]]
128- command = " apply"
129- options = {code =" mario_addons.plugins.addons.read_csv(x, header=header)" }
127+ [[ command .stage ]]
128+ command = " apply"
129+ options = {code =" mario_addons.plugins.addons.read_csv(x, header=header)" }
130130
131- [[ alias .stage ]]
132- command = " chain"
131+ [[ command .stage ]]
132+ command = " chain"
133133
134- [[ alias .stage ]]
135- command = " map"
136- options = {code =" dict(x)" }
134+ [[ command .stage ]]
135+ command = " map"
136+ options = {code =" dict(x)" }
137137
138- [[ alias .test ]]
139- invocation = [" read-csv" ]
140- input = """ name,age\n Alice,21\n Bob,22\n """
141- output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
138+ [[ command .test ]]
139+ invocation = [" read-csv" ]
140+ input = """ name,age\n Alice,21\n Bob,22\n """
141+ output = """ {'name': 'Alice', 'age': '21'}\n {'name': 'Bob', 'age': '22'}\n """
142142
143143
144- [[alias ]]
144+ [[command ]]
145145name = " read-yaml"
146- help = " Read yaml document"
146+ short_help = " Read yaml document"
147147section = " Read"
148148
149- [[alias .stage ]]
149+ [[command .stage ]]
150150command = " stack"
151151options = {code =" yaml.safe_load" }
152152
153- [[alias .test ]]
153+ [[command .test ]]
154154invocation = [" read-yaml" ]
155155input = " {'x': 1,}\n "
156156output = " {'x': 1}\n "
157157
158- [[alias ]]
158+ [[command ]]
159159name = ' write-json'
160- help = " Write json document"
160+ short_help = " Write json document"
161161section = " Write"
162162
163- [[alias .stage ]]
163+ [[command .stage ]]
164164command = " apply"
165165options ={code =" json.dumps" }
166166
167- [[alias .test ]]
167+ [[command .test ]]
168168invocation = [" stack" , " str.split" , " write-json" ]
169169input = " 1 2\n "
170170output =" [[\" 1\" , \" 2\" ]]\n "
171171
172172
173-
174-
175- [[alias ]]
173+ [[command ]]
176174name = ' write-toml'
177- help = " Write toml document"
175+ short_help = " Write toml document"
178176section = " Write"
179177
180- [[alias .stage ]]
178+ [[command .stage ]]
181179command = " map"
182180options ={code =" toml.dumps" }
183181
184- [[alias .test ]]
182+ [[command .test ]]
185183invocation = [" stack" , " json.loads" , " write-toml" ]
186184input = ''' {"x": 1}
187185'''
0 commit comments