slyce 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +17 -4
  3. data/bin/slyced +2 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1327a9e50802b5e802b1be542681b0c7d051d13e2fd354f20dd12a28b46c14c0
4
- data.tar.gz: cf79a752ce4346d7a0d3a5756ec564e92b512ad454d7e567c89757575c0d334e
3
+ metadata.gz: 2ba003aec5b58e63630c2b5fc40437ecfc841e8b2c2239fea6fba2cc785687d8
4
+ data.tar.gz: 3713c8ea0c95383fad5151012553a4f22fba837925d19839bcef5abadba1b2d6
5
5
  SHA512:
6
- metadata.gz: eeaf579fd814d9db6c1120ec2cab9291acad26a14d8c30bbca3585c173b05909e25812c84af2f3524586baba162e0c71429300aff49d5a912444c96a8dbf4fc7
7
- data.tar.gz: abfcf38eeac61002eefe660ff95fabfeadf7439aa60beb33908ac95c2bbd1b1375ceeeb954b4bdaa08a4687a5b2f8f4b316757e9fb78e8fd27a79723277124a4
6
+ metadata.gz: e93706e9acd8ce49b35d1c47c19cffb388ab3e77dbe1cdeff9f1e817c3b89d5b854edbafb1422951d82b4a395c63882cf6f267c4bff772597a830ea13cc98c42
7
+ data.tar.gz: cec5303f23cd5e5370c349e566f1afed2d5a7f3a6b094aede4ba7c851aeaf2ef76f58adfe1148660b3e852bfea4923ade8dab40ae73e9c656560f55a210f05d6
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.0"
14
+ @version = "1.3.1"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -23,9 +23,10 @@ OptionParser.new.instance_eval do
23
23
  on "-n", "--natural" , "Sort naturally, not numerically"
24
24
  on "-r", "--rows <count>" , "Rows of data to show", Integer
25
25
  on "-s", "--suppress" , "Suppress header when exporting delimited files"
26
+ on "-t", "--tables" , "Display table names and quit"
26
27
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
27
28
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
28
- on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
29
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns (or tables) to extract"
29
30
 
30
31
  self
31
32
  end.parse!(into: opts={}) rescue abort($!.message)
@@ -43,7 +44,7 @@ show = opts[:rows ]
43
44
  want = opts[:extract].to_s.downcase.split(",")
44
45
 
45
46
  dbas ||= ARGV.shift or abort "no database given"
46
- tabl ||= ARGV.shift or abort "no table given"
47
+ tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
47
48
 
48
49
  [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
49
50
 
@@ -75,6 +76,7 @@ end
75
76
 
76
77
  # ==[ Let 'er rip! ]==
77
78
 
79
+ # get database connection
78
80
  if dbas.include?("/")
79
81
  dbas = $' if dbas =~ %r|^mysql://| # drop mysql:// prefix, if present
80
82
  auth, dbas = dbas.split("/", 2)
@@ -95,7 +97,18 @@ else
95
97
  end
96
98
 
97
99
  conn = Mysql2::Client.new(**conf, as: :array)
98
- resu = conn.query("select * from `#{tabl}` limit 0")
100
+
101
+ # get table names
102
+ if tabl.nil? || opts[:tables]
103
+ resu = conn.sql("show tables")
104
+ tbls = resu.to_a.flatten
105
+ want = (want.empty? || opts[:tables]) ? tbls : want.select {|e| tbls.include?(e) }
106
+ puts want
107
+ exit
108
+ end
109
+
110
+ # get column names
111
+ resu = conn.sql("select * from `#{tabl}` limit 0")
99
112
  cols = resu.fields
100
113
  want = want.empty? ? cols : want.select {|e| cols.include?(e) }
101
114
 
data/bin/slyced CHANGED
@@ -11,7 +11,7 @@ dbas = nil
11
11
  tabl = nil
12
12
 
13
13
  OptionParser.new.instance_eval do
14
- @version = "1.3.0"
14
+ @version = "1.3.1"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -25,7 +25,7 @@ OptionParser.new.instance_eval do
25
25
  on "-s", "--suppress" , "Suppress header when exporting delimited files"
26
26
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
27
27
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
28
- on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
28
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns to extract"
29
29
 
30
30
  self
31
31
  end.parse!(into: opts={}) rescue abort($!.message)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: any_ascii