relaton-cli 1.16.0 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d96e141da8f193b480b52e742609971db8358e90819b9cdd1a3406141c8e9c5
4
- data.tar.gz: 684e2c529cbd077e58f526b421e62c2bea874eb0167c11e2601e3212546eca80
3
+ metadata.gz: 5d7cc2a49bdf10f53e244e9953bed1ac4590f4cc2ea14685c768200425d1fb71
4
+ data.tar.gz: 8e2e6b11df808211aee56ac2ae1ee1edfd3aa5e159e72ca95a403255af24034f
5
5
  SHA512:
6
- metadata.gz: 430b486d9df71df93ce4dd1a8c1d306cae8df2018766cbc0a8f886ac2ec09c40678b62541e448427b9f63a94d49b6ae1705fa14c4ed54277191ecd9b6b869547
7
- data.tar.gz: d83743a5a0fd38719f083bee3e1f373848d6111d70915592fa0262f569468918dfebecf5ee7745e5cd9a76a5ba70f1c64c336f5e18718c4aa1d5ea1838e2c148
6
+ metadata.gz: bc4a898e2fa561aa3b8b91d74f1897fdd22f765c9a3c36c1d14f94d018c7644599e513a7a946408ba8f2dccc91a694744ed9e27df07d1b3e4d6af30eb8599b7f
7
+ data.tar.gz: 1b1730b2fc45f5d1af3477e58d4163b3b4a84460b4e587d1ccd9a881a672337a9e053fa0b938a83952a652345fec0abd74ac65ad9cc3a647ccdaa946439a4639
data/docs/README.adoc CHANGED
@@ -42,17 +42,18 @@ suports an additional `-x` or `--extension` options to use different extension.
42
42
 
43
43
  [source,console]
44
44
  ----
45
- $ relaton fetch CODE -t TYPE -f FORMAT -y YEAR -r RETRIES --all-parts --keep-year
45
+ $ relaton fetch CODE -t TYPE -f FORMAT -y YEAR -r RETRIES --all-parts --keep-year --no-cache
46
46
  ----
47
47
 
48
48
  Fetch the Relaton XML entry corresponding to the document identifier `CODE`.
49
49
 
50
50
  * `YEAR` is optional and specifies the year of publication of the standard.
51
51
  * `FORMAT` is optional, and specifies the output format; the recognized values for `FORMAT` are `xml` (default), yaml, `bibtex`.
52
- * `TYPE` is optional and specifies the standards class library to be used, that the identifier is part of. The recognized values for `TYPE` are `3GPP, BIPM, BSI, CC, CEN, CIE, CN, ECMA, IANA, IEC, IEEE, IETF, IHO, ISO, ITU, NIST, OGC, OMG, UN, W3C`.
52
+ * `TYPE` is optional and specifies the standards class library to be used, that the identifier is part of. The recognized values for `TYPE` are `3GPP, BIPM, BSI, CC, CCSDS, CEN, CIE, CN, ECMA, IANA, IEC, IEEE, IETF, IHO, ISO, ITU, NIST, OASIS, OGC, OMG, UN, W3C, XSF`.
53
53
  * `RETRIES` is optional, number of network retries (default 1).
54
54
  * `--all-parts` fetch all parts.
55
55
  * `--keep-year` undated reference should return an actual reference with year.
56
+ * `--no-cache` do not use cache.
56
57
 
57
58
  === relaton fetch-data
58
59
 
@@ -392,10 +393,10 @@ Creates a new database in a directory `DIR` (optional, deafult is `/home/USER/.r
392
393
 
393
394
  ----
394
395
  $ relaton db create
395
- Database is in "/Users/user/.relaton/cache"
396
+ [relaton-cli] Database is in `/Users/user/.relaton/cache`
396
397
 
397
398
  $ relaton db create cachedb
398
- Database is in "/Users/user/RubyProjects/relaton-cli/cachedb"
399
+ [relaton-cli] Database is in `/Users/user/RubyProjects/relaton-cli/cachedb`
399
400
  ----
400
401
 
401
402
  ==== Move database
@@ -408,7 +409,7 @@ Move database to another place `DIR`.
408
409
 
409
410
  ----
410
411
  $ relaton db mv cache_dir
411
- Database is moved to "/Users/user/RubyProjects/relaton-cli/cache_dir"
412
+ [relaton-cli] Database is moved to `/Users/user/RubyProjects/relaton-cli/cache_dir`
412
413
  ----
413
414
 
414
415
  ==== Clear database
@@ -20,16 +20,17 @@ module Relaton
20
20
  end
21
21
 
22
22
  desc "fetch CODE", "Fetch Relaton XML for Standard identifier CODE"
23
- option :type, aliases: :t, desc: "Type of standard to " \
24
- "get bibliographic entry for"
25
- option :format, aliases: :f, desc: "Output format (xml, yaml, bibtex). " \
26
- "Default xml."
23
+ option :type, aliases: :t,
24
+ desc: "Type of standard to get bibliographic entry for"
25
+ option :format, aliases: :f,
26
+ desc: "Output format (xml, yaml, bibtex). Default xml."
27
27
  option :year, aliases: :y, type: :numeric, desc: "Year the standard was published"
28
28
  option :"all-parts", type: :boolean, desc: "Fetch all parts"
29
- option :"keep-year", type: :boolean, desc: "Undated reference should " \
30
- "return actual reference with year"
31
- option :retries, aliases: :r, type: :numeric, desc: "Number of network " \
32
- "retries. Default 1."
29
+ option :"keep-year", type: :boolean,
30
+ desc: "Undated reference should return actual reference with year"
31
+ option :retries, aliases: :r, type: :numeric,
32
+ desc: "Number of network retries. Default 1."
33
+ option :"no-cache", type: :boolean, desc: "Ignore cache"
33
34
 
34
35
  def fetch(code)
35
36
  io = IO.new($stdout.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
@@ -160,10 +161,9 @@ module Relaton
160
161
 
161
162
  no_commands do
162
163
  def relaton_config
163
- log_types = %i[info error]
164
- log_types << :warning if options[:verbose]
164
+ log_type = options[:verbose] ? ::Logger::INFO : ::Logger::WARN
165
165
  Relaton.configure do |conf|
166
- conf.logs = log_types
166
+ conf.logger.level = log_type
167
167
  end
168
168
  end
169
169
  end
@@ -177,12 +177,13 @@ module Relaton
177
177
  # @option options [String, NilClass] :format
178
178
  # @option options [Integer, NilClass] :year
179
179
  # @return [String, nil]
180
- def fetch_document(code, options) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
180
+ def fetch_document(code, options) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize,Metrics/MethodLength
181
181
  year = options[:year]&.to_s
182
+ dup_opts = options.dup.transform_keys { |k| k.to_s.gsub("-", "_").to_sym }
182
183
  if (processor = Relaton::Registry.instance.by_type options[:type]&.upcase)
183
- doc = Relaton.db.fetch_std code, year, processor.short, options.dup
184
+ doc = Relaton.db.fetch_std code, year, processor.short, **dup_opts
184
185
  elsif options[:type] then return
185
- else doc = Relaton.db.fetch(code, year, options.dup)
186
+ else doc = Relaton.db.fetch(code, year, **dup_opts)
186
187
  end
187
188
  return "No matching bibliographic entry found" unless doc
188
189
 
@@ -0,0 +1,12 @@
1
+ module Relaton
2
+ module Cli
3
+ module Config
4
+ include RelatonBib::Config
5
+ end
6
+ extend Config
7
+
8
+ class Configuration < RelatonBib::Configuration
9
+ PROGNAME = "relaton-cli".freeze
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module Relaton
4
4
  def fetch(source, options)
5
5
  processor = Relaton::Registry.instance.find_processor_by_dataset source
6
6
  unless processor
7
- warn "[relaton-cli] WARNING: no processor found for #{source}"
7
+ Util.warn "WARNING: no processor found for `#{source}`"
8
8
  return
9
9
  end
10
10
 
@@ -18,7 +18,7 @@ module Relaton
18
18
  file_path = File.join dir, file
19
19
  col = Relaton::Bibcollection.new options
20
20
  if File.exist? file_path
21
- warn "Collection #{file} aready exist"
21
+ Util.warn "Collection `#{file}` aready exist"
22
22
  else
23
23
  FileUtils.mkdir_p dir # unless Dir.exist? dir
24
24
  File.write file_path, col.to_yaml, encoding: "UTF-8"
@@ -114,7 +114,7 @@ module Relaton
114
114
  coll = read_collection colfile
115
115
  coll << doc
116
116
  File.write colfile, coll.to_yaml, encoding: "UTF-8"
117
- else warn "No matching bibliographic entry found"
117
+ else Util.warn "No matching bibliographic entry found"
118
118
  end
119
119
  end
120
120
 
@@ -161,11 +161,12 @@ module Relaton
161
161
  end
162
162
 
163
163
  # @param file [String]
164
- # @return [Hash]
164
+ # @return [Hash, nil]
165
165
  def read_yaml(file)
166
166
  YAML.load_file file if File.file? file
167
167
  rescue Psych::SyntaxError
168
- warn "[relaton-cli] WARNING: the file #{file} isn't a collection."
168
+ Util.warn "WARNING: the file `#{file}` isn't a collection."
169
+ nil
169
170
  end
170
171
 
171
172
  # @param file [String]
@@ -10,7 +10,7 @@ module Relaton
10
10
  def create(dir = nil)
11
11
  db = Relaton.db (dir && File.expand_path(dir))
12
12
  path = db.instance_variable_get(:@db).dir
13
- warn "Cache DB is in \"#{path}\""
13
+ Util.warn "Cache DB is in `#{path}`"
14
14
  end
15
15
 
16
16
  desc "mv DIR", "Move cache DB to a new directory"
@@ -20,7 +20,7 @@ module Relaton
20
20
  path = Relaton.db.mv new_path
21
21
  if path
22
22
  File.write Cli::RelatonDb::DBCONF, path, encoding: "UTF-8"
23
- warn "Cache DB is moved to \"#{path}\""
23
+ Util.warn "Cache DB is moved to `#{path}`"
24
24
  end
25
25
  end
26
26
 
@@ -29,7 +29,7 @@ module Relaton
29
29
  def clear
30
30
  db = Relaton.db
31
31
  db.clear
32
- warn "Cache DB is cleared"
32
+ Util.warn "Cache DB is cleared"
33
33
  end
34
34
 
35
35
  desc "fetch CODE", "Fetch Relaton XML for Standard identifier CODE " \
@@ -0,0 +1,11 @@
1
+ module Relaton
2
+ module Cli
3
+ module Util
4
+ extend RelatonBib::Util
5
+
6
+ def self.logger
7
+ Relaton::Cli.configuration.logger
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Cli
3
- VERSION = "1.16.0".freeze
3
+ VERSION = "1.16.1".freeze
4
4
  end
5
5
  end
data/lib/relaton/cli.rb CHANGED
@@ -2,6 +2,8 @@ require "thor"
2
2
  require "thor/hollaback"
3
3
  require "relaton"
4
4
  require "relaton/cli/version"
5
+ require_relative "cli/config"
6
+ require_relative "cli/util"
5
7
  require_relative "cli/command"
6
8
 
7
9
  module Relaton
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-03 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -98,11 +98,13 @@ files:
98
98
  - lib/relaton/cli.rb
99
99
  - lib/relaton/cli/base_convertor.rb
100
100
  - lib/relaton/cli/command.rb
101
+ - lib/relaton/cli/config.rb
101
102
  - lib/relaton/cli/data_fetcher.rb
102
103
  - lib/relaton/cli/full_text_search.rb
103
104
  - lib/relaton/cli/relaton_file.rb
104
105
  - lib/relaton/cli/subcommand_collection.rb
105
106
  - lib/relaton/cli/subcommand_db.rb
107
+ - lib/relaton/cli/util.rb
106
108
  - lib/relaton/cli/version.rb
107
109
  - lib/relaton/cli/xml_convertor.rb
108
110
  - lib/relaton/cli/xml_to_html_renderer.rb