relaton-cli 1.4.0 → 1.7.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +46 -0
- data/Gemfile +0 -1
- data/docs/README.adoc +202 -7
- data/lib/relaton/bibcollection.rb +53 -35
- data/lib/relaton/bibdata.rb +3 -1
- data/lib/relaton/cli.rb +71 -32
- data/lib/relaton/cli/base_convertor.rb +1 -1
- data/lib/relaton/cli/command.rb +123 -61
- data/lib/relaton/cli/full_text_search.rb +91 -0
- data/lib/relaton/cli/relaton_file.rb +1 -1
- data/lib/relaton/cli/subcommand_collection.rb +221 -0
- data/lib/relaton/cli/subcommand_db.rb +73 -0
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_to_html_renderer.rb +14 -7
- data/lib/relaton/cli/yaml_convertor.rb +1 -1
- data/lib/relaton/element_finder.rb +5 -5
- data/relaton-cli.gemspec +7 -6
- data/templates/_index.liquid +9 -1
- metadata +34 -33
- data/.github/workflows/macos.yml +0 -32
- data/.github/workflows/ubuntu.yml +0 -32
- data/.github/workflows/windows.yml +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c0e11fa51a48417dd591d2835b2637a79f9a021e58f1f1fb6e818d12e90ac3
|
4
|
+
data.tar.gz: da5753170d30401fab1a0b013a338ee3cd48da9d209a5ee17e83700f0999e59d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee2b8248080c68d64cc58e780e0aa77ba0ad9bd06d6e42ce4e8eda81c639bb2e5dd301e177cad0bdc12f3bd7d588a7f2b7f1eab9c426d1c81e6ef53e66e61a4
|
7
|
+
data.tar.gz: ed00bade15a250b8dcaa6d531c58ca1b979ad5a73175eb97a63593f1525ae62c4002f477e3bd84a717fdc571919e43f8021980c40d0e6dc9aba1282b050c6a51
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '3.0'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '3.0'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '3.0'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
with:
|
35
|
+
submodules: true
|
36
|
+
|
37
|
+
# https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
|
38
|
+
- if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
|
39
|
+
run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
|
40
|
+
|
41
|
+
- uses: ruby/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
44
|
+
bundler-cache: true
|
45
|
+
|
46
|
+
- run: bundle exec rake
|
data/Gemfile
CHANGED
data/docs/README.adoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= Relaton CLI (relaton-cli): Relaton Command-line Interface
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/relaton-cli.svg["Gem Version", link="https://rubygems.org/gems/relaton-cli"]
|
4
|
-
image:https://github.com/relaton/relaton-cli/workflows/
|
5
|
-
image:https://github.com/relaton/relaton-cli/workflows/macos/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=macos"]
|
6
|
-
image:https://github.com/relaton/relaton-cli/workflows/windows/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=windows"]
|
4
|
+
image:https://github.com/relaton/relaton-cli/workflows/rake/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=rake"]
|
7
5
|
image:https://codeclimate.com/github/metanorma/relaton-cli/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/relaton-cli"]
|
8
6
|
|
9
7
|
Documentation in development.
|
@@ -43,15 +41,17 @@ suports an additional `-x` or `--extension` options to use different extension.
|
|
43
41
|
|
44
42
|
[source,console]
|
45
43
|
----
|
46
|
-
$ relaton fetch CODE -t TYPE -f FORMAT -y YEAR
|
44
|
+
$ relaton fetch CODE -t TYPE -f FORMAT -y YEAR -r RETRIES --all-parts --keep-year
|
47
45
|
----
|
48
46
|
|
49
47
|
Fetch the Relaton XML entry corresponding to the document identifier `CODE`.
|
50
48
|
|
51
49
|
* `YEAR` is optional, and specifies the year of publication of the standard.
|
52
|
-
* `FORMAT` is optional, and specifies the output format; the recognised values for `FORMAT` are `xml` (default), `bibtex`.
|
53
|
-
* `TYPE` specifies the standards class library to be used, that the identifier is part of
|
54
|
-
|
50
|
+
* `FORMAT` is optional, and specifies the output format; the recognised values for `FORMAT` are `xml` (default), yaml, `bibtex`.
|
51
|
+
* `TYPE` is optional, specifies the standards class library to be used, that the identifier is part of. The recognised values for `TYPE` are `BIPM`, `CC`, `CIE`, `CN`, `ECMA`, `IEC`, `IEEE`, `IETF`, `IHO`, `ISO`, `ITU`, `NIST`, `OGC`, `OMG`, `UN`, `W3C`.
|
52
|
+
* `RETRIES` is optional, number of network retries (default 1).
|
53
|
+
* `--all-parts` fetch all parts.
|
54
|
+
* `--keep-year` undated reference should return actual reference with year.
|
55
55
|
|
56
56
|
=== relaton extract
|
57
57
|
|
@@ -217,3 +217,198 @@ $ relaton convert XML -f FORMAT -o OUTPUT-FILE
|
|
217
217
|
----
|
218
218
|
|
219
219
|
Convert a Relaton XML document into YAML, AsciiBib, or BibTex format. Allowed -f or --format options are yaml, asciibib, bibtex. If the option -o or --output is omitted then a new file will be created in the folder where the original file is, with the same name but another appropriated extension.
|
220
|
+
|
221
|
+
=== relaton collection
|
222
|
+
|
223
|
+
The `relaton collection` is a set of subcommands for collections manipulations.
|
224
|
+
|
225
|
+
==== relaton collection create
|
226
|
+
|
227
|
+
----
|
228
|
+
$ relaton collection create COLLECTION -d DIRECTORY --author AUTHOR --title TITLE --doctype DOCTYPE
|
229
|
+
----
|
230
|
+
|
231
|
+
Create new empty collection with name `COLLECTION`.
|
232
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
233
|
+
* `AUTHOR`, `TITLE`, and `DOCTYPE` are optional.
|
234
|
+
|
235
|
+
==== relaton collection info
|
236
|
+
|
237
|
+
----
|
238
|
+
$ relaton collection info COLLECTION -d DIRECTORY
|
239
|
+
----
|
240
|
+
|
241
|
+
Show information about `COLLECTION` (number of items, file size of collection, last updated, name, metadata).
|
242
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
243
|
+
|
244
|
+
==== relaton collection list
|
245
|
+
|
246
|
+
----
|
247
|
+
$ relaton collection list -d DIRECTORY -e
|
248
|
+
----
|
249
|
+
|
250
|
+
List all collections.
|
251
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
252
|
+
* When parametr `-e` is defined the id of each entry id will be listed.
|
253
|
+
|
254
|
+
==== relaton collection get
|
255
|
+
|
256
|
+
----
|
257
|
+
$ relaton collection get CODE -c COLLECTION -d DIRECTORY -f FORMAT -o FILE
|
258
|
+
----
|
259
|
+
|
260
|
+
Get a document matched to `CODE` from `COLLECTION`.
|
261
|
+
|
262
|
+
* `COLLECTION` is optional name of collection. If undefined then fetch the first match across all collections in `DIRECTORY`.
|
263
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
264
|
+
* `FORMAT` is optional. If udefined then print documern in a human-readable form. Allowed values are `abb` (AsciiBib) or `xml` (XML).
|
265
|
+
* `FILE` is optional. When it's defined then save document with given file name. File's extension defines format of the file. Possible extensions are `abb` (AsciiBib) or `xml` (XML).
|
266
|
+
|
267
|
+
==== relaton collection find
|
268
|
+
|
269
|
+
----
|
270
|
+
$ relaton collection find TEXT -c COLLECTION -d DIRECTORY
|
271
|
+
----
|
272
|
+
|
273
|
+
Full-text search through a collection or all collections.
|
274
|
+
|
275
|
+
* `COLLECTION` is optional name of collection. If udefined then search across all collections.
|
276
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
277
|
+
|
278
|
+
==== relaton collection fetch
|
279
|
+
|
280
|
+
----
|
281
|
+
$ relaton collection fetch CODE -t TYPE -y YEAR -c COLLECTION -d DIRECTORY
|
282
|
+
----
|
283
|
+
|
284
|
+
Fetch the Relaton XML entry corresponding to the document identifier `CODE` and save it into `COLLECTION`.
|
285
|
+
|
286
|
+
* `TYPE` specifies the standards class library to be used, that the identifier is part of. The recognised values for `TYPE` are `BIPM`, `CC`, `CN`, `IEC`, `IEEE`, `IETF`, `IHO`, `ISO`, `ITU`, `NIST`, `OGC`, `OMG`, `UN`, `W3C`.
|
287
|
+
* `YEAR` is optional, and specifies the year of publication of the standard.
|
288
|
+
* `COLLECTION` is a name of collection.
|
289
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
290
|
+
|
291
|
+
==== relaton collection export
|
292
|
+
|
293
|
+
----
|
294
|
+
$ relaton collection export COLLECTION -d DIRECTORY
|
295
|
+
----
|
296
|
+
|
297
|
+
Export `COLLECTION` into XML file.
|
298
|
+
|
299
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
300
|
+
|
301
|
+
==== relaton collection import
|
302
|
+
|
303
|
+
----
|
304
|
+
$ relaton collection import FILE -c COLLECTION -d DIRECTORY
|
305
|
+
----
|
306
|
+
|
307
|
+
Import document or collection from XML `FILE` into `COLLECTION`.
|
308
|
+
|
309
|
+
* `COLLECTION` is optional. If collection doesn't exist then it will be created.
|
310
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
311
|
+
|
312
|
+
=== Cache DB manipulation
|
313
|
+
|
314
|
+
==== Create caache DB
|
315
|
+
|
316
|
+
----
|
317
|
+
$ relaton db create DIR
|
318
|
+
----
|
319
|
+
|
320
|
+
Creates a new cache DB in a directory `DIR` (optional, deafult is `/home/USER/.relaton/dbpath`). In case the target directory exists it will be used as a cache DB.
|
321
|
+
|
322
|
+
----
|
323
|
+
$ relaton db create
|
324
|
+
Cache DB is in "/Users/user/.relaton/cache"
|
325
|
+
|
326
|
+
$ relaton db create cachedb
|
327
|
+
Cache DB is in "/Users/user/RubyProjects/relaton-cli/cachedb"
|
328
|
+
----
|
329
|
+
|
330
|
+
==== Move cache DB
|
331
|
+
|
332
|
+
----
|
333
|
+
$ relaton db mv DIR
|
334
|
+
----
|
335
|
+
|
336
|
+
Move cache DB to another place `DIR`.
|
337
|
+
|
338
|
+
----
|
339
|
+
$ relaton db mv cache_dir
|
340
|
+
Cache DB is moved to "/Users/user/RubyProjects/relaton-cli/cache_dir"
|
341
|
+
----
|
342
|
+
|
343
|
+
==== Clear cache DB
|
344
|
+
|
345
|
+
Delete all entries from a chache DB.
|
346
|
+
|
347
|
+
----
|
348
|
+
$ relaton db clear
|
349
|
+
----
|
350
|
+
|
351
|
+
==== Fetch from cache DB
|
352
|
+
|
353
|
+
----
|
354
|
+
$ relaton db fetch -t TYPE -f FORMAT -y YEAR
|
355
|
+
----
|
356
|
+
|
357
|
+
Fetch an entry from a cache DB. See [relaton fetch](#relaton-fetch) for the arguments explanation.
|
358
|
+
|
359
|
+
==== Fetch all
|
360
|
+
|
361
|
+
Fetch all entries from a chache DB.
|
362
|
+
|
363
|
+
----
|
364
|
+
$ relaton db fetch_all TEXT -e EDITION -y YEAR -f FORMAT
|
365
|
+
----
|
366
|
+
|
367
|
+
* `TEXT` (optional) search for a certan string
|
368
|
+
* `EDITION` (optional) filter documets with a certain edition
|
369
|
+
* `YEAR` (optional) filter documents by a year
|
370
|
+
* `FORMAT` (optional) specify the output format. Recognised values are `xml` (default), yaml, `bibtex`.
|
371
|
+
|
372
|
+
----
|
373
|
+
$ relaton db fetch_all
|
374
|
+
<bibitem id="ISO/IECDIR1" type="international-standard">
|
375
|
+
...
|
376
|
+
|
377
|
+
$ relaton db fetch_all 'Procedures for the technical work'
|
378
|
+
<bibitem id="ISO/IECDIR1" type="international-standard">
|
379
|
+
<fetched>2021-04-01</fetched>
|
380
|
+
<title type="title-main" format="text/plain" language="en" script="Latn">Procedures for the technical work</title>
|
381
|
+
...
|
382
|
+
|
383
|
+
$ relaton db fetch_all -e 3
|
384
|
+
<bibitem id="ISO2146-2010" type="standard">
|
385
|
+
...
|
386
|
+
<edition>3</edition>
|
387
|
+
...
|
388
|
+
|
389
|
+
$ relaton db fetch_all -e 8 -y 2018
|
390
|
+
<bibitem id="ISO/IECDIR2IEC" type="international-standard">
|
391
|
+
<fetched>2021-04-01</fetched>
|
392
|
+
<title type="title-main" format="text/plain" language="en" script="Latn">Principles and rules for the structure and drafting of ISO and IEC documents</title>
|
393
|
+
<uri type="obp">https://www.iec.ch/members_experts/refdocs/iec/isoiecdir2%7Bed8.0.RLV%7Den.pdf</uri>
|
394
|
+
<docidentifier type="ISO">ISO/IEC DIR 2 IEC</docidentifier>
|
395
|
+
<date type="published">
|
396
|
+
<on>2018-05-01</on>
|
397
|
+
</date>
|
398
|
+
<edition>8</edition>
|
399
|
+
...
|
400
|
+
----
|
401
|
+
|
402
|
+
==== Get document type
|
403
|
+
|
404
|
+
----
|
405
|
+
$ relaton db doctype REF
|
406
|
+
----
|
407
|
+
|
408
|
+
Takes a reference `REF` and retuern a document type.
|
409
|
+
|
410
|
+
----
|
411
|
+
$ relaton db doctype 'CN(GB/T 1.1)'
|
412
|
+
Chinese Standard
|
413
|
+
GB/T 1.1
|
414
|
+
----
|
@@ -8,36 +8,34 @@ module Relaton
|
|
8
8
|
|
9
9
|
attr_accessor *ATTRIBS
|
10
10
|
|
11
|
-
#
|
12
|
-
|
11
|
+
# @param options [Hash]
|
13
12
|
def initialize(options)
|
14
|
-
self.items = []
|
15
13
|
ATTRIBS.each do |k|
|
16
14
|
value = options[k] || options[k.to_s]
|
17
15
|
send("#{k}=", value)
|
18
16
|
end
|
19
|
-
|
20
|
-
acc << if item.is_a?(Bibcollection) || item.is_a?(Bibdata)
|
21
|
-
item
|
22
|
-
else new_bib_item_class(item)
|
23
|
-
end
|
24
|
-
end
|
17
|
+
reduce_items
|
25
18
|
end
|
26
|
-
# rubocop:enable Metrics/MethodLength
|
27
19
|
|
28
20
|
# arbitrary number, must sort after all bib items
|
29
21
|
def doc_number
|
30
22
|
9999999
|
31
23
|
end
|
32
24
|
|
25
|
+
# Add a dcoument to the collection
|
26
|
+
# @param item [RelatonBib::BibliographicItem]
|
27
|
+
def <<(item)
|
28
|
+
items << new_bib_item_class(item)
|
29
|
+
end
|
30
|
+
|
33
31
|
# rubocop:disable Metrics/MethodLength
|
34
32
|
|
35
33
|
# @param source [Nokogiri::XML::Element]
|
36
34
|
def self.from_xml(source)
|
37
35
|
title = find_text("./relaton-collection/title", source)
|
38
36
|
author = find_text(
|
39
|
-
"./relaton-collection/contributor[role/@type='author']/organization/
|
40
|
-
source
|
37
|
+
"./relaton-collection/contributor[role/@type='author']/organization/"\
|
38
|
+
"name", source
|
41
39
|
)
|
42
40
|
|
43
41
|
items = find_xpath("./relaton-collection/relation", source)&.map do |item|
|
@@ -48,29 +46,8 @@ module Relaton
|
|
48
46
|
|
49
47
|
new(title: title, author: author, items: items)
|
50
48
|
end
|
51
|
-
# rubocop:enable Metrics/MethodLength
|
52
|
-
|
53
|
-
def new_bib_item_class(options)
|
54
|
-
if options.is_a?(Hash) && options["items"]
|
55
|
-
::Relaton::Bibcollection.new(options)
|
56
|
-
else
|
57
|
-
::Relaton::Bibdata.new(options)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def items_flattened
|
62
|
-
items.sort_by! &:docnumber
|
63
|
-
|
64
|
-
items.reduce([]) do |acc,item|
|
65
|
-
acc << if item.is_a? ::Relaton::Bibcollection
|
66
|
-
item.items_flattened
|
67
|
-
else
|
68
|
-
item
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
49
|
|
73
|
-
# rubocop:disable Metrics/AbcSize
|
50
|
+
# rubocop:disable Metrics/AbcSize
|
74
51
|
|
75
52
|
# @param opts [Hash]
|
76
53
|
# @return [String] XML
|
@@ -98,7 +75,37 @@ module Relaton
|
|
98
75
|
end
|
99
76
|
ret += "</relaton-collection>\n"
|
100
77
|
end
|
101
|
-
# rubocop:enable Metrics/AbcSize
|
78
|
+
# rubocop:enable Metrics/AbcSize
|
79
|
+
|
80
|
+
# @param item [Hash, RelatonBib::BibliographicItem, Relatin::Bibdata,
|
81
|
+
# Relaton::Bibcollection]
|
82
|
+
# @return [Relaton::Bibdata, Relaton::Bibcollection]
|
83
|
+
def new_bib_item_class(item)
|
84
|
+
if item.is_a?(Hash)
|
85
|
+
if item["items"]
|
86
|
+
::Relaton::Bibcollection.new(item)
|
87
|
+
else
|
88
|
+
bibitem = ::Relaton::Cli::YAMLConvertor.convert_single_file item
|
89
|
+
::Relaton::Bibdata.new bibitem
|
90
|
+
end
|
91
|
+
elsif item.is_a?(Relaton::Bibdata) || item.is_a?(Relaton::Bibcollection)
|
92
|
+
item
|
93
|
+
else ::Relaton::Bibdata.new(item)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# rubocop:enable Metrics/MethodLength
|
97
|
+
|
98
|
+
def items_flattened
|
99
|
+
items.sort_by! &:doc_number
|
100
|
+
|
101
|
+
items.reduce([]) do |acc, item|
|
102
|
+
acc << if item.is_a? ::Relaton::Bibcollection
|
103
|
+
item.items_flattened
|
104
|
+
else
|
105
|
+
item
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
102
109
|
|
103
110
|
def to_yaml
|
104
111
|
to_h.to_yaml
|
@@ -116,5 +123,16 @@ module Relaton
|
|
116
123
|
|
117
124
|
{ "root" => a }
|
118
125
|
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def reduce_items
|
130
|
+
self.items = (items || []).reduce([]) do |acc, item|
|
131
|
+
acc << if item.is_a?(Bibcollection) || item.is_a?(Bibdata)
|
132
|
+
item
|
133
|
+
else new_bib_item_class(item)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
119
137
|
end
|
120
138
|
end
|
data/lib/relaton/bibdata.rb
CHANGED
@@ -4,8 +4,10 @@ module Relaton
|
|
4
4
|
class Bibdata
|
5
5
|
URL_TYPES = %i[uri xml pdf doc html rxl txt].freeze
|
6
6
|
|
7
|
+
# @return [RelatonBib::BibliographicItem]
|
7
8
|
attr_reader :bibitem
|
8
9
|
|
10
|
+
# @param bibitem [RelatonBib::BibliographicItem]
|
9
11
|
def initialize(bibitem)
|
10
12
|
@bibitem = bibitem
|
11
13
|
end
|
@@ -44,7 +46,7 @@ module Relaton
|
|
44
46
|
options = { bibdata: true, date_format: :full }.merge(
|
45
47
|
opts.select { |k, _v| k.is_a? Symbol }
|
46
48
|
)
|
47
|
-
@bibitem.to_xml
|
49
|
+
@bibitem.to_xml **options
|
48
50
|
end
|
49
51
|
|
50
52
|
def to_h
|