prick 0.17.0 → 0.18.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: 70b51ae69f1d1cb0c2c27666273b0564d78f950de870104865203362258d40a2
4
- data.tar.gz: e3b46dbc411282c05977940551246a8bfff7689889648ac7e481974c67ef326f
3
+ metadata.gz: 22580f7a2f37e4ad59c6354e3b6ac1d7bb6f5eb7fe8f44eddb941ba715f8fa39
4
+ data.tar.gz: b0b5bf43389a0e35c6a739b92b4e50b043cb75ab1e215aa109a9a68e4f17e1e3
5
5
  SHA512:
6
- metadata.gz: 0431efaa5b92fe0497f642bb5bd4f115f533417122c9f7f71d6de17aa7c65128d79c4a74cfe82ac8fa18b88d9b3aff6905744a3129f62b63f865c64d0e63292f
7
- data.tar.gz: 8e01993d41040f3d4db9f10d4aa461b420b81a5116836ba1cbb0cb298b75b2e9beaeb61ce3982ed21496ee459ab76e3f28ddf98c6f40fa17ad28c5f49ffcc97e
6
+ metadata.gz: 7768a47145ae07f6ae99e808ad513107ccd98327fc009311cd0bfde1f1dbd3a52a3d9f5061c6bb3918b12da6850b0cf4e5242efade679d950a603047c8dd9cfc
7
+ data.tar.gz: e2709800fe62d599bba1ea64960b4a09e8a97a87da3d60731e8293f4957c9ac35147122dea16220481b9c49b17d3cf31377663f1328b99608c0fc3cc84ca4ad9
data/lib/prick/builder.rb CHANGED
@@ -60,6 +60,7 @@ module Prick
60
60
 
61
61
  protected
62
62
  def do_dir(path, &block)
63
+ # puts "do_dir(#{path.inspect})"
63
64
  dir, file = File.split(path)
64
65
  Dir.chdir(dir) { yield(file) }
65
66
  end
@@ -82,10 +83,11 @@ module Prick
82
83
  true
83
84
  end
84
85
 
85
- def do_exe(path, schema: nil)
86
- # puts "do_exe(#{path})"
86
+ def do_exe(path, args = [], schema: nil)
87
+ # puts "do_exe(#{path.inspect}, #{args.inspect})"
87
88
  do_dir(path) { |file|
88
- lines = Command.command "./#{file} #{database.name} #{database.user}" # FIXME Security
89
+ cmd = (["./#{file}"] + args).join(" ")
90
+ lines = Command.command cmd, stdin: [database.name, database.user]
89
91
  if @execute
90
92
  begin
91
93
  Rdbms.exec_sql(database.name, lines.join("\n"), user: database.user, schema: schema)
@@ -110,8 +112,9 @@ module Prick
110
112
 
111
113
  # A subject can be both an abstract subject or a concrete file (*.yml, *.sql)
112
114
  def build_subject(subject)
113
- if File.file?(subject) && File.executable?(subject)
114
- do_exe(subject)
115
+ cmd, *args = subject.split(/\s+/)
116
+ if File.file?(cmd) && File.executable?(cmd)
117
+ do_exe(cmd, args)
115
118
  elsif File.file?(subject) && subject.end_with?(".yml")
116
119
  do_yml(subject)
117
120
  elsif File.file?(subject) && subject.end_with?(".sql")
@@ -193,9 +196,9 @@ module Prick
193
196
  super(path, schema: schema)
194
197
  end
195
198
 
196
- def do_exe(path)
199
+ def do_exe(path, args = [])
197
200
  schema = Dir.getwd.sub(/^.*schema\/([^\/]+)(?:\/.*)?$/, '\1')
198
- super(path, schema: schema)
201
+ super(path, args, schema: schema)
199
202
  end
200
203
  end
201
204
  end
data/lib/prick/command.rb CHANGED
@@ -15,14 +15,17 @@ module Command
15
15
  end
16
16
 
17
17
  # Execute the shell command 'cmd' and return standard output as an array of
18
- # strings while stderr is passed through unless stderr: is false. If stderr:
18
+ # strings. while stderr is passed through unless stderr: is false. If stderr:
19
19
  # is true, it returns a tuple of [stdout, stderr] instead. The shell command
20
20
  # is executed with the `errexit` and `pipefail` bash options
21
+ #
22
+ # The :stdin option is a line or an array of lines that'll be fed to the
23
+ # standard input of the command. Default is nil
21
24
  #
22
25
  # It raises a Command::Error exception if the command fails unless :fail is
23
26
  # true. The exit status of the last command is stored in ::status
24
27
  #
25
- def command(cmd, stderr: false, fail: true)
28
+ def command(cmd, stdin: nil, stderr: false, fail: true)
26
29
  cmd = "set -o errexit\nset -o pipefail\n#{cmd}"
27
30
 
28
31
  pw = IO::pipe # pipe[0] for read, pipe[1] for write
@@ -52,12 +55,18 @@ module Command
52
55
  pr[1].close
53
56
  pe[1].close
54
57
 
58
+ if stdin
59
+ pw[1].puts(stdin)
60
+ pw[1].flush
61
+ pw[1].close
62
+ end
63
+
55
64
  @status = Process.waitpid2(pid)[1].exitstatus
56
65
 
57
66
  out = pr[0].readlines.collect { |line| line.chop }
58
67
  err = pe[0].readlines.collect { |line| line.chop }.grep_v(/^NOTICE:/)
59
68
 
60
- pw[1].close
69
+ pw[1].close if !stdin
61
70
  pr[0].close
62
71
  pe[0].close
63
72
 
data/lib/prick/version.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Required by gem
6
6
  module Prick
7
- VERSION = "0.17.0"
7
+ VERSION = "0.18.0"
8
8
  end
9
9
 
10
10
  # Project related code starts here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-19 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shellopts