sqlbible 1.10.0 → 1.11.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: 435728b125a8af87f99d9e0227de96a537f4525274ebdae22191d9de1f2d04a8
4
- data.tar.gz: bba7f1ceb9626222a92a18773491764be9944261a55f42998cf17328d9034e44
3
+ metadata.gz: 00d0eddffface8289cb8f02462cb0a0c34a39cffbf67af85fd6f9296dbde400e
4
+ data.tar.gz: 53ca66961559c13d285388d474a7ca25c5212afde1d38c4aa7c9e1fd853f7b1f
5
5
  SHA512:
6
- metadata.gz: e3deefdfdd74197c1b95cf1db6c2983694f759f4ffd2abd393ff7d69b7949557e5cacd1057f9cf365dfd6dcefe10c240381ecbe64e3c50664f00cfcd97ff737a
7
- data.tar.gz: e0eaf3f6270f5feda71c454fe0aa11de540e8081cc180a4027db86ee94ed912426e0ae3a7fd1c860532dae374aa156ab5be7f0d8b90f8da2e6509d788077f9a7
6
+ metadata.gz: 544453d67a715d6f93ece6ad6d2275a83bc847cfafd1a3af5f35874406378cc6038d2acca2143fc9893096bd378a3492caeba86f25f9ab2dc2ea79409579ddd8
7
+ data.tar.gz: b529a999009a32d33107153ba6fca72cec02b532cdb183c0dc44e98faa1a2d221bf45e7a6d088c18644161e60ad5baf2db74ea69c1747c11f7514d2174b93022
data/bin/sqlbible CHANGED
@@ -22,19 +22,74 @@ class Cli
22
22
  private
23
23
 
24
24
  def parse_args
25
+ if ARGV.empty?
26
+ reline_args
27
+ @opts = parsed_opts
28
+ else
29
+ @opts = parsed_opts
30
+ if @opts[:interactive]
31
+ reline_args
32
+ opts = parsed_opts
33
+ opts.each_pair do |k, v|
34
+ if k.to_s =~ /^(.+)_given$/
35
+ new_k = $1.to_sym
36
+ @opts[new_k] = opts[new_k]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ @regexes = ARGV.map {|s| Regexp.new(s)}
42
+ end
43
+
44
+ def reline_args
45
+ load_history
46
+ loop do
47
+ l = Reline.readline('> ', false)&.chomp
48
+ break if l.nil? || l =~ /^$/
49
+ if l =~ /^-/
50
+ l.split(/\s+/, 2).each do |s|
51
+ ARGV << s
52
+ end
53
+ else
54
+ ARGV << l
55
+ end
56
+ if Sqlbible.history && !Reline::HISTORY.include?(l)
57
+ Reline::HISTORY << l
58
+ end
59
+ end
60
+ rescue Interrupt
61
+ exit
62
+ ensure
63
+ write_history
64
+ end
65
+
66
+ def load_history
67
+ if Sqlbible.history && File.exist?(Sqlbible.history_file)
68
+ File.readlines(Sqlbible.history_file, chomp: true).each do |line|
69
+ Reline::HISTORY << line unless line.empty?
70
+ end
71
+ end
72
+ end
73
+
74
+ def write_history
75
+ max_history = Reline::HISTORY.to_a.last(100)
76
+ return if max_history.empty?
77
+ File.write(Sqlbible.history_file, max_history.join("\n") + "\n")
78
+ end
79
+
80
+ def parsed_opts
25
81
  default_bible_param = {}
26
82
  if b = Sqlbible.bible
27
83
  default_bible_param[:default] = b.to_s
28
84
  end
29
- explizit_opts = Set.new
30
-
31
- @opts = Optimist.options do
85
+ opts = Optimist.options do
32
86
  synopsis 'Usage: sqlbible [options] [search regexes]*'
33
87
  opt :bible, 'Name of the bible module or filename of an .sqlbible file', type: String, **default_bible_param
34
88
  opt :color, 'Colorize output', default: Sqlbible.color do |v|
35
89
  explizit_opts << :color
36
90
  end
37
91
  opt :env, 'Show infos of the sqlbible environment: installed bibles with schema versions'
92
+ opt :interactive, 'Interactive mode'
38
93
  opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
39
94
  opt :output, 'Output filename', type: String
40
95
  opt :pager, 'Use pager for terminal output', default: Sqlbible.pager
@@ -42,14 +97,12 @@ class Cli
42
97
  opt :stat, 'Statistics level', type: Integer, permitted: (0..2), default: Sqlbible.stat_level
43
98
  version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
44
99
  end
45
-
46
- unless explizit_opts.include? :color
47
- if !$stdout.tty? || @opts[:output]
48
- @opts[:color] = false
100
+ unless opts[:color_given]
101
+ if !$stdout.tty? || opts[:output]
102
+ opts[:color] = false
49
103
  end
50
104
  end
51
-
52
- @regexes = ARGV.map {|s| Regexp.new(s)}
105
+ opts
53
106
  end
54
107
 
55
108
  def process_by_opts
@@ -179,22 +232,4 @@ class Cli
179
232
 
180
233
  end
181
234
 
182
- # interactive mode
183
- if ARGV.empty?
184
- begin
185
- while (l = Reline.readline('> ', false))
186
- break if l.empty?
187
- if l =~ /^-/
188
- l.split(/\s+/, 2).each do |s|
189
- ARGV << s
190
- end
191
- else
192
- ARGV << l
193
- end
194
- end
195
- rescue Interrupt
196
- exit
197
- end
198
- end
199
-
200
235
  Cli.new.run
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Sqlbible
5
- VERSION = '1.10.0'
5
+ VERSION = '1.11.0'
6
6
  end
data/lib/sqlbible.rb CHANGED
@@ -84,6 +84,8 @@ class Sqlbible
84
84
  @bibles_dir = File.join(Dir.home, '.sqlbible/bibles')
85
85
  @color_reference = :blue
86
86
  @color_emphasize = :underline
87
+ @history = true
88
+ @history_file = File.join(Dir.home, '.sqlbible/history')
87
89
  @lang = :en
88
90
  @pager_command = 'less -FRSX'
89
91
  @stat_level = 1
@@ -91,7 +93,7 @@ class Sqlbible
91
93
  class << self
92
94
 
93
95
  attr_reader :bibles_dir
94
- attr_accessor :color, :color_reference, :color_emphasize, :bible, :lang, :pager, :pager_command, :stat_level
96
+ attr_accessor :bible, :color, :color_emphasize, :color_reference, :history, :history_file, :lang, :pager, :pager_command, :stat_level
95
97
 
96
98
  # Get the database schema as string
97
99
  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.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich