Debian Codegraph @

bin/catmandu

raw
1 #!perl
2
3 use Catmandu;
4 use Catmandu::CLI;
5 use Cwd ();
6
7 Catmandu->default_load_path(Cwd::getcwd);
8 Catmandu::CLI->run // exit(2);
9
10 =head1 NAME
11
12 catmandu - LibreCat command line tools
13
14 =head1 SYNOPSIS
15
16 catmandu [-D|-D2|-D3] [-I path] [-L path] [COMMAND] [-?hqv] [long options...] [ARGS]
17
18 catmandu --version
19
20 catmandu help
21
22 # convert
23 catmandu convert JSON to YAML < file.json
24 catmandu convert YAML to JSON < file.yaml
25 catmandu convert YAML < file.yaml # 'to JSON' is implicit
26 catmandu convert MARC < records.mrc
27 catmandu convert MARC --fix 'marc_map(245,title)' < records.mrc
28 catmandu convert MARC --fix myfixes.txt < records.mrc
29 catmandu convert OAI --url https://biblio.ugent.be/oai
30 catmandu convert SRU --base http://www.unicat.be/sru --query dna
31
32 # import
33 catmandu import JSON to MongoDB --database_name mydb < records.json
34 catmandu import MARC to MongoDB --database_name mydb < records.mrc
35 catmandu import MARC to ElasticSearch --index_name mydb < records.mrc
36 catmandu import MARC to ElasticSearch --index_name mydb --fix 'marc_map("245a","title")' < records.mrc
37
38 # export
39 catmandu export MongoDB --database_name mydb --bag data to JSON
40 catmandu export MongoDB --database_name mydb --bag data to JSON --fix 'retain("_id")'
41 catmandu export Solr --url http://localhost:8983/solr to JSON
42 catmandu export ElasticSearch --index_name mydb to JSON
43
44 # copy
45 catmandu copy MongoDB --database_name mydb to ElasticSearch --index_name mydb
46
47 # show the contents of catmandu.yml
48 catmandu config
49
50 # count items in a store
51 catmandu count test1
52
53 # delete items from store
54 catmandu delete test1 -q 'title:"My Rabbit"'
55
56 # run a fix script
57 $ catmandu run myfixes.fix
58
59 # or, create an executable fix script
60 $ cat myfixes.fix
61 #!/usr/local/bin/catmandu run
62 do importer(OAI,url:"http://biblio.ugent.be/oai")
63 retain(_id)
64 end
65 $ chmod 755 myfixes.fix
66 $ ./myfixes.fix
67
68 # configuration
69 $ cat catmandu.yml
70 ---
71 store:
72 test1:
73 package: MongoDB
74 options:
75 database_name: mydb
76 catmandu import JSON to test1 < records.json
77
78 # show installed commands
79 $ catmandu info
80 $ catmandu info --namespace XML
81
82 =head1 COMMANDS
83
84 =head2 help COMMAND
85
86 Documentation about command line options.
87
88 =head2 config
89
90 Display the contents of the catmandu.yml files in your project.
91
92 =head2 convert IMPORTER [OPTIONS] [[--fix FIX]] to EXPORTER [OPTIONS]
93
94 Convert data from one format to another format with help of L<Catmandu::Importer>s and
95 L<Catmandu::Exporter>s. All options given on the command line will be send to the Importer
96 or Exporter as initialization parameters. E.g.
97
98 catmandu convert OAI --url BASEURL --metadataPrefx PREFIX \
99 to \
100 CSV --header 1 --sep_char '|'
101
102 Look at the documentation of all the importers and exporters to see which options are
103 available.
104
105 All importers accept one or more --fix options with the name of a fix file or file command.
106
107 catmandu convert JSON --fix fixes.txt
108 catmandu convert JSON --fix 'remove_field(abc)'
109
110 The JSON exporter is implicit and is optional.
111
112 catmandu convert YAML to JSON
113 catmandu convert YAML # shorter
114
115 =head2 copy STORE [OPTIONS] [-q QUERY] [--limit LIMIT] [[--fix FIX]] to STORE [OPTIONS]
116
117 Copy items from one L<Catmandu::Store> to another. All options given
118 on the command line will be send to the Stores as initialization parameters.
119 Optionally a QUERY and LIMIT can be provided to selectively export items from the Store.
120 Optionally a FIX can be provided to be executed on all the items before they are
121 stored.
122
123 =head2 count STORE [OPTIONS]
124
125 Count the number of items in a L<Catmandu::Store>. All options given on the command line
126 will be send to the store as initialization parameters. E.g.
127
128 catmandu count MongoDB --database_name mydb --bag data
129
130 =head2 delete STORE [OPTIONS] [-q QUERY]
131
132 Delete items from a L<Catmandu::Store>. All options given on the command line
133 will be send to the store as initialization parameters. Optionally a QUERY can
134 be provided to select the items to delete. E.g.
135
136 catmandu delete MongoDB --database_name mydb --bag data -q "title:Delete me"
137
138 =head2 export STORE [OPTIONS] [-q QUERY] [--limit LIMIT] [[--fix FIX]] to EXPORTER [OPTIONS]
139
140 Export items from a L<Catmandu::Store> using a L<Catmandu::Exporter>. All options given
141 on the command line will be send to the Store or Exporter as initialization parameters.
142 Optionally a QUERY and LIMIT can be provided to selectively export items from the Store.
143 Optionally a FIX can be provided to be executed on all the items before they are
144 exporter by the exporter.
145
146 E.g.
147
148 catmandu export MongoDB --database_name mydb --bag data -q "title:Perl"
149
150 =head2 import IMPORTER [OPTIONS] [[--fix FIX]] to STORE [OPTIONS]
151
152 Import items from a L<Catmandu::Importer> to a L<Catmandu::Store>. All options given
153 on the command line will be send to the Importer or Store as initialization parameters.
154 Optionally a FIX can be provided to be executed on all the items before they are
155 stored into the Store.
156
157 catmandu import JSON to MongoDB --database_name mydb < records.json
158
159 =head2 info [OPTIONS]
160
161 List installed Catmandu modules (importers, exporters, stores, and fixes).
162
163 =head2 run [FIX]
164
165 Execute a fix script or run an interactive Fix shell.
166
167 =head1 OPTIONS
168
169 =over 4
170
171 =item -v
172
173 Verbose output. This includes progress of operations.
174
175 =item -h
176
177 =item -?
178
179 =item --lib-path PATH
180
181 =item -I
182
183 Specifies Perl library include paths, like perl's -I option. This option is
184 repeatable.
185
186 =item --load-path PATH
187
188 =item -L PATH
189
190 Search upwards from this path for configuration files and accompanying lib
191 directories. This option is repeatable.
192
193 =item --var [NAME]=[VALUE]
194
195 Catmandu such as convert, import and export accept command line variables
196 that can be read by any fix script provided. For instance, if provenance
197 information need to be added to the output, then this can be provided
198 via the command line:
199
200 $ catmandu convert MARC --fix myfixes.txt --var source=Springer --var date=2016 < data.mrc
201
202 with myfixes.txt a file like:
203
204 add_field(source,{{source}})
205 add_field(data,{{date}})
206 ...(other fixes)...
207
208 =item --debug [LEVEL]
209
210 =item -D[LEVEL]
211
212 Set the debugging level for Catmandu. LEVEL is one of:
213
214 1 - WARN messages
215 2 - INFO messages
216 3 - DEBUG messages
217
218 Requires an installation of L<Log::Log4perl> and L<Log::Any::Adapter::Log4perl>. By
219 default an internal log4perl configuration file is used that sends all debug messages
220 to stderr. Optionally in the catmandu.yml the path to a log4perl configuration file
221 can be set. E.g.
222
223 catmandu.yml:
224
225 log4perl: /etc/log4perl.conf
226
227 or
228
229 log4perl: "
230 log4perl.category.Catmandu=$level,$appender
231
232 log4perl.appender.STDOUT=Log::Log4perl::Appender::Screen
233 log4perl.appender.STDOUT.stderr=0
234 log4perl.appender.STDOUT.utf8=1
235
236 log4perl.appender.STDOUT.layout=PatternLayout
237 log4perl.appender.STDOUT.layout.ConversionPattern=%d [%P] - %p %l %M time=%r : %m%n
238
239 log4perl.appender.STDERR=Log::Log4perl::Appender::Screen
240 log4perl.appender.STDERR.stderr=0
241 log4perl.appender.STDERR.utf8=1
242
243 log4perl.appender.STDERR.layout=PatternLayout
244 log4perl.appender.STDERR.layout.ConversionPattern=%d [%P] - %l : %m%n
245 "
246
247 See also L<Catmandu::Logger> to enable logging for your own Catmandu packages.
248
249 =back
250
251 =head1 DATA OPTIONS
252
253 =over 4
254
255 =item --fix EXPRESSION
256
257 =item --fix FILE
258
259 When exporting or storing apply a fix EXPRESSION or all the fixes in FILE on
260 each item. This option is repeatable.
261
262 =item --start NUM
263
264 When exporting or storing data skip the first NUM items.
265
266 =item --total NUM
267
268 When exporting of storing data process only a total NUM of items.
269
270 =item --replace
271
272 When storing data first delete all the items in the Store or Bag.
273
274 =item --query QUERY
275
276 =item --cql-query QUERY | -q QUERY
277
278 When a Store is searchable execute and return the results. Using the --cql-query or -q
279 option the CQL query language can be used (if supported).
280
281 =item --sort SORT
282
283 =item --sru-sortkeys SORT
284
285 Set the sort order for the results returned from a searchable Store. --sru-sortkeys
286 is only available if the Store supports CQL.
287
288 =item --limit NUM
289
290 Limit the number of results returned from the searchable results to NUM.
291
292 =item --count
293
294 Report the number of items processed.
295
296 =item --version
297
298 Return the installed version of Catmandu.
299
300 =back
301
302 =head1 SEE ALSO
303
304 L<Catmandu::Importer>
305 L<Catmandu::Exporter>
306 L<Catmandu::Store>
307 L<Catmandu::MARC>
308 L<Catmandu::OAI>
309 L<Catmandu::MongoDB>
310 L<Catmandu::Solr>
311 L<Catmandu::ElasticSearch>
312
313 =cut