prick 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/prick/builder.rb +10 -7
- data/lib/prick/command.rb +12 -3
- data/lib/prick/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22580f7a2f37e4ad59c6354e3b6ac1d7bb6f5eb7fe8f44eddb941ba715f8fa39
|
4
|
+
data.tar.gz: b0b5bf43389a0e35c6a739b92b4e50b043cb75ab1e215aa109a9a68e4f17e1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
114
|
-
|
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
|
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
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.
|
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-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shellopts
|