slyce 1.3.2 → 1.3.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +17 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d593f1fb756c6af9643dfa496027cb39cd85451f351d3dd2541cbfa340b1c7b3
4
- data.tar.gz: 13753300c5bbebb1b40998bc1cb1c9397b0a2c9ab2691fb9a21f0de1252c3b68
3
+ metadata.gz: 00d9ddd3a6d353a87ede364090e7b534adeb9f0f7c2bc64c374db8dcf9e181d9
4
+ data.tar.gz: 2b22b3ee7f996cda2c5770af031fc8fa65db652d54b70bd16bcea03247ce9d3d
5
5
  SHA512:
6
- metadata.gz: d11b2bad746f523480a8bdcc8659f64e381e63803cabfe4311741f3fe7f40129bfcd65dc1374ef77842c3f4bb2896d4280c2eb4697e1ff66a8c6f04f45d78657
7
- data.tar.gz: 8da310dc995ca7b73439081666e9e6c62bc56fb9be8e06f8076976ee624923058a2f867f8a326a13c0e76c99391677d670f70cc482117fcc71b634812e5780d2
6
+ metadata.gz: d91171715f18698c3ced8c1f7a0a7eca87d28766a2b99e7272950760cc21f3cc6eab626f57f45d5adbd2e6b33590c04e56f6d55a8427241ecc31ff45d7506d74
7
+ data.tar.gz: 3ea0f1d215bb9bb0a4c6cc70b7e579e61a7e7167950f83ec48e27bbb88f987df571da4b0bf31ee772ef3214768fa0b2df43f0d20af6dd80effa809a462a7846c
data/bin/slyce CHANGED
@@ -11,7 +11,7 @@ dbas = nil
11
11
  tabl = nil
12
12
 
13
13
  OptionParser.new.instance_eval do
14
- @version = "1.3.2"
14
+ @version = "1.3.3"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -19,7 +19,7 @@ OptionParser.new.instance_eval do
19
19
  on "--tsv" , "Output tab separated values"
20
20
  on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
21
21
  on "-c", "--columns" , "Display column names and quit"
22
- on "-d", "--dump" , "Display table schema and quit"
22
+ on "-d", "--dump" , "Dump database schema and quit"
23
23
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
24
24
  on "-n", "--natural" , "Sort naturally, not numerically"
25
25
  on "-r", "--rows <count>" , "Rows of data to show", Integer
@@ -27,7 +27,7 @@ OptionParser.new.instance_eval do
27
27
  on "-t", "--tables" , "Display table names and quit"
28
28
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
29
29
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
30
- on "-x", "--extract <a,b,c...>" , "Comma separated list of columns (or tables) to extract"
30
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns or tables to extract"
31
31
 
32
32
  self
33
33
  end.parse!(into: opts={}) rescue abort($!.message)
@@ -38,11 +38,12 @@ xtsv = opts[:tsv]
38
38
  xprt = xcsv || xpsv || xtsv and require "censive"
39
39
 
40
40
  asky = opts[:ascii ] and require "any_ascii"
41
- filt = opts[:where ] and filt = "where\n #{filt}"
42
- hide = opts[:suppress]
41
+ dump = opts[:dump]
42
+ want = opts[:extract ].to_s.downcase.split(",")
43
43
  natu = opts[:natural ]
44
44
  show = opts[:rows ]
45
- want = opts[:extract].to_s.downcase.split(",")
45
+ hide = opts[:suppress]
46
+ filt = opts[:where ] and filt = "where\n #{filt}"
46
47
 
47
48
  dbas ||= ARGV.shift or abort "no database given"
48
49
  tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
@@ -78,7 +79,9 @@ end
78
79
  # ==[ Let 'er rip! ]==
79
80
 
80
81
  # get database connection
81
- if dbas.include?("/")
82
+ if !dbas.include?("/")
83
+ conf = { database: dbas }
84
+ else
82
85
  dbas = $' if dbas =~ %r|^mysql://| # drop mysql:// prefix, if present
83
86
  auth, dbas = dbas.split("/", 2)
84
87
  if auth =~ /^(?:(\w+)(?::([^@]+))?@)?(?:([^:]+)?(?::(\d+))?)$/
@@ -93,20 +96,19 @@ if dbas.include?("/")
93
96
  else
94
97
  abort "invalid database value #{dbas.inspect}"
95
98
  end
96
- else
97
- conf = { database: dbas }
98
99
  end
99
100
 
100
101
  conn = Mysql2::Client.new(**conf, as: :array)
101
102
 
102
- # get table names
103
- if tabl.nil? || opts[:dump] || opts[:tables]
103
+ # dump database schema or show table names
104
+ if tabl.nil? || opts[:tables] || opts[:dump]
105
+
106
+ # get table names
104
107
  resu = conn.sql("show tables")
105
108
  tbls = resu.to_a.flatten
106
- want = (want.empty? || opts[:tables]) ? tbls : want.select {|e| tbls.include?(e) }
107
-
108
- #!# FIXME: this code is a mess... cleanup soon
109
+ want = (want.empty? || opts[:tables] || opts[:dump]) ? tbls : want.select {|e| tbls.include?(e) }
109
110
 
111
+ # dump database schema
110
112
  if opts[:dump]
111
113
  pict = "%Y-%m-%dT%H:%M:%S%z"
112
114
  puts "-- Dump of `#{dbas}` database on #{Time.now.strftime(pict)}\n\n"
@@ -125,6 +127,7 @@ if tabl.nil? || opts[:dump] || opts[:tables]
125
127
  exit
126
128
  end
127
129
 
130
+ # show table names
128
131
  puts want
129
132
  exit
130
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve