sqlbible 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72978515d6a27e67112ec446a6445914dc71041dfd9cd0cd4e5f9b62c9fbc80f
4
- data.tar.gz: ef2db40ffe61d3f87520420034094d633dd14569d1d11e827b3e0ef2e4896a35
3
+ metadata.gz: b56764d9e3209aadc3d033fdb8870ebf7b32aeed2c036527ad0211f637890db4
4
+ data.tar.gz: 61562839dd855f990b6eebcafd375453e1e70e66d38574c3755cbcbb4a0c9c86
5
5
  SHA512:
6
- metadata.gz: 930dc1198d988f112623304f6651601e415860b0e24f3ef7cd4dc26be270605f7e8917a1f103fa14f76570e455863469bca4a49d44e9201f21fbc7eb8e0be38c
7
- data.tar.gz: 32b6f1b61a08bb377104e24099a87a4ea69a2df30d3f2216460cc0b8760076ddb768c512b355b08d983774b253d005fab7d0f75c12fb0418347ebb2ac562e761
6
+ metadata.gz: b3b396178ca096c2d153ffb241099c0d2bfdc7981d5b4bd8a0e033fd125e1a13231c4cf1f8c85309725fcd2067e37f63f31529149b5829aadf4744d534221c6c
7
+ data.tar.gz: 2e5d47096a3023c4510f44359db1683ac3e4d08ba597c2178c9d04365d14f30a7158c0f292cf965b7bb73d8ccf50a32a5bf6924e473a29ccb0a437a3edcc8318
data/README.md CHANGED
@@ -42,6 +42,7 @@ See help of the command-line application:
42
42
 
43
43
  ```shell
44
44
  sqlbible -h
45
+ sqlbible-convert -h
45
46
  ```
46
47
 
47
48
  ## Requirements
data/bin/sqlbible CHANGED
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # frozen_string_literal: false
4
4
 
5
- require 'optimist_xl'
5
+ require 'optimist'
6
6
  require 'scripref'
7
7
  require 'sqlbible'
8
8
  require 'sqlbible/ansicolor'
@@ -12,41 +12,30 @@ if b = Sqlbible.bible
12
12
  default_bible_param[:default] = b.to_s
13
13
  end
14
14
 
15
- unless $stdout.tty?
16
- Sqlbible.colorize = false
17
- end
15
+ $explizit_opts = Set.new
18
16
 
19
- result = OptimistXL.options do
20
- synopsis 'Usage: sqlbible <command> [options] [filename]?'
21
- subcmd :convert, 'Convert a bible from OSIS-XML to Sqlbible format' do
22
- opt :bible, 'Name of the converted bible module or output filename of the generated .sqlbible file', type: String, required: true
23
- opt :overwrite, 'Overwrite existing module or output file if exist', type: :Boolean, default: false
24
- end
25
- subcmd :list, 'Show a list of the names of the bibles in central directory'
26
- subcmd :search, 'Search with regular expressions' do
27
- opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String, **default_bible_param
28
- opt :colorize, 'Colorize output' do |v|
29
- Sqlbible.colorize = v
30
- end
31
- opt :search, 'Regular expression to search (multiple allowed)', type: String, multi: true, required: true
32
- opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
33
- opt :output, 'Output filename', type: String
34
- opt :range, 'Search range, example: "John 1-10"', type: String
35
- end
36
- subcmd :text, 'Show text of references' do
37
- opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String, **default_bible_param
38
- opt :colorize, 'Colorize output' do |v|
39
- Sqlbible.colorize = v
40
- end
41
- opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
42
- opt :output, 'Output filename', type: String
43
- opt :reference, 'Reference to show, example: "John 3:16; 10:27-30"', type: String, required: true
17
+ $opts = Optimist.options do
18
+ synopsis 'Usage: sqlbible [options] [search regexes]*'
19
+ opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String, **default_bible_param
20
+ opt :color, 'Colorize output', default: Sqlbible.color do |v|
21
+ $explizit_opts << :color
44
22
  end
23
+ opt :info, 'Show infos for installed bibles'
24
+ opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
25
+ opt :output, 'Output filename', type: String
26
+ opt :pager, 'Use pager for terminal output', default: Sqlbible.pager
27
+ opt :reference, 'Reference to show or search, example: "John 3:16; 10:27-30"', type: String
45
28
  version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
46
29
  end
47
30
 
48
- def determine_lang_mod subopts
49
- case l = subopts[:lang]
31
+ unless $explizit_opts.include? :color
32
+ if !$stdout.tty? || $opts[:output]
33
+ $opts[:color] = false
34
+ end
35
+ end
36
+
37
+ def determine_lang_mod
38
+ case l = $opts[:lang]
50
39
  when 'en', nil
51
40
  Scripref::English
52
41
  when 'de'
@@ -56,17 +45,23 @@ def determine_lang_mod subopts
56
45
  end
57
46
  end
58
47
 
59
- def determine_out subopts
60
- if fn = subopts[:output]
61
- out = File.open(fn, 'w')
48
+ def open_out
49
+ if fn = $opts[:output]
50
+ File.open(fn, 'w') do |f|
51
+ yield f
52
+ end
53
+ elsif $opts[:pager]
54
+ IO.popen(Sqlbible.pager_command, 'w') do |p|
55
+ yield p
56
+ end
62
57
  else
63
- out = $stdout
58
+ yield $stdout
64
59
  end
65
60
  end
66
61
 
67
62
  def format_verse_ref f, v
68
63
  ref = f.format(v.scripref_passage)
69
- if Sqlbible.colorize
64
+ if $opts[:color]
70
65
  Ansicolor.apply(ref, Sqlbible.color_reference)
71
66
  else
72
67
  ref
@@ -75,7 +70,7 @@ end
75
70
 
76
71
  def format_text v, regexes
77
72
  text = v.plaintext.gsub("\n", ' ¶')
78
- if Sqlbible.colorize
73
+ if $opts[:color]
79
74
  regexes.each do |re|
80
75
  text = text.gsub(re, Ansicolor.apply('\0', Sqlbible.color_emphasize))
81
76
  end
@@ -87,56 +82,36 @@ def format_verse_line f, v, regexes=[]
87
82
  format('%s: %s', format_verse_ref(f, v), format_text(v, regexes))
88
83
  end
89
84
 
90
- subopts = result.subcommand_options
91
-
92
85
  begin
93
- case result.subcommand
94
- when 'convert'
95
- require 'fileutils'
96
- require 'sqlbible/convert'
97
- unless osis_fn = result.leftovers.first
98
- fail 'no filename given'
99
- end
100
- sqlbible_fn = Sqlbible.resolve_db_filename(subopts[:bible])
101
- if !subopts[:overwrite] && File.exist?(sqlbible_fn)
102
- fail format('file %s exist, conversion aborted', sqlbible_fn)
103
- end
104
- unless File.exist?(dir = Sqlbible.bibles_dir)
105
- puts format('create directory %s', dir)
106
- FileUtils.mkdir_p dir
107
- end
108
- if $stdout.tty?
109
- puts "convert #{osis_fn} to #{sqlbible_fn} ..."
110
- end
111
- Sqlbible.convert osis_fn, sqlbible_fn
112
- when 'list'
113
- puts 'Available bible names:'
114
- puts Sqlbible.bible_names.join("\n")
115
- when 'search'
116
- searches = subopts[:search]
117
- lang_mod = determine_lang_mod(subopts)
118
- if r = subopts[:range]
119
- p = Scripref::Parser.new(lang_mod)
120
- range = p.parse(r)
121
- else
122
- range = nil
86
+ if $opts[:info]
87
+ names = Sqlbible.bible_names
88
+ max_size = names.map(&:size).max
89
+ names.each do |n|
90
+ puts format("%-#{max_size}s (schema version: %s)", n, Sqlbible.new(n).schema_version)
123
91
  end
124
- out = determine_out(subopts)
125
- bible = Sqlbible.new(subopts[:bible])
126
- regexes = searches.map {|s| Regexp.new(s)}
127
- f = Scripref::Formatter.new(lang_mod, abbrev_level: 1)
128
- bible.search(regexes, range: range).each do |v|
129
- out.puts format_verse_line(f, v, regexes)
92
+ return
93
+ end
94
+ lang_mod = determine_lang_mod
95
+ p = Scripref::Parser.new(lang_mod)
96
+ f = Scripref::Formatter.new(lang_mod, abbrev_level: 1)
97
+ if r = $opts[:reference]
98
+ ref = p.parse(r)
99
+ else
100
+ ref = nil
101
+ end
102
+ bible = Sqlbible.new($opts[:bible])
103
+ if ARGV.size > 0
104
+ regexes = ARGV.map {|s| Regexp.new(s)}
105
+ open_out do |out|
106
+ bible.search(regexes, range: ref).each do |v|
107
+ out.puts format_verse_line(f, v, regexes)
108
+ end
130
109
  end
131
- when 'text'
132
- lang_mod = determine_lang_mod(subopts)
133
- p = Scripref::Parser.new(lang_mod)
134
- f = Scripref::Formatter.new(lang_mod, abbrev_level: 1)
135
- ref = p.parse(subopts[:reference])
136
- bible = Sqlbible.new(subopts[:bible])
137
- out = determine_out subopts
138
- bible.reference(ref).flatten.each do |v|
139
- out.puts format_verse_line(f, v)
110
+ else
111
+ open_out do |out|
112
+ bible.reference(Array(ref)).flatten.each do |v|
113
+ out.puts format_verse_line(f, v)
114
+ end
140
115
  end
141
116
  end
142
117
  rescue Exception => e
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # frozen_string_literal: false
4
+
5
+ require 'optimist'
6
+ require 'sqlbible'
7
+ require 'fileutils'
8
+ require 'sqlbible/convert'
9
+
10
+ opts = Optimist.options do
11
+ synopsis 'Usage: sqlbible [options] [filename]'
12
+ opt :bible, 'Name of the converted bible module or output filename of the generated .sqlbible file', type: String, required: true
13
+ opt :overwrite, 'Overwrite existing module or output file if exist', type: :Boolean, default: false
14
+ version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
15
+ end
16
+
17
+ begin
18
+ unless osis_fn = ARGV.first
19
+ fail 'no filename given'
20
+ end
21
+ sqlbible_fn = Sqlbible.resolve_db_filename(opts[:bible])
22
+ if !opts[:overwrite] && File.exist?(sqlbible_fn)
23
+ fail format('file %s exist, conversion aborted', sqlbible_fn)
24
+ end
25
+ unless File.exist?(dir = Sqlbible.bibles_dir)
26
+ puts format('create directory %s', dir)
27
+ FileUtils.mkdir_p dir
28
+ end
29
+ if $stdout.tty?
30
+ puts "convert #{osis_fn} to #{sqlbible_fn} ..."
31
+ end
32
+ Sqlbible.convert osis_fn, sqlbible_fn
33
+ rescue Exception => e
34
+ $stderr.puts e.message
35
+ exit 1
36
+ end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Sqlbible
5
- VERSION = '1.7.1'
5
+ VERSION = '1.9.0'
6
6
  end
data/lib/sqlbible.rb CHANGED
@@ -85,11 +85,12 @@ class Sqlbible
85
85
  @color_reference = :blue
86
86
  @color_emphasize = :underline
87
87
  @lang = :en
88
+ @pager_command = 'less -FRSX'
88
89
 
89
90
  class << self
90
91
 
91
92
  attr_reader :bibles_dir
92
- attr_accessor :colorize, :color_reference, :color_emphasize, :bible, :lang
93
+ attr_accessor :color, :color_reference, :color_emphasize, :bible, :lang, :pager, :pager_command
93
94
 
94
95
  # Get the database schema as string
95
96
  def db_schema
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlbible
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
@@ -38,19 +38,19 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.16'
40
40
  - !ruby/object:Gem::Dependency
41
- name: optimist_xl
41
+ name: optimist
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '3.3'
46
+ version: '3.2'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '3.3'
53
+ version: '3.2'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: scripref
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -124,12 +124,14 @@ dependencies:
124
124
  email: janfri26@gmail.com
125
125
  executables:
126
126
  - sqlbible
127
+ - sqlbible-convert
127
128
  extensions: []
128
129
  extra_rdoc_files: []
129
130
  files:
130
131
  - LICENSE
131
132
  - README.md
132
133
  - bin/sqlbible
134
+ - bin/sqlbible-convert
133
135
  - lib/sqlbible.rb
134
136
  - lib/sqlbible/ansicolor.rb
135
137
  - lib/sqlbible/convert.rb
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  - !ruby/object:Gem::Version
154
156
  version: '0'
155
157
  requirements: []
156
- rubygems_version: 4.1.0.dev
158
+ rubygems_version: 4.0.6
157
159
  specification_version: 4
158
160
  summary: Library for bibles as SQLite databases
159
161
  test_files: []