spud 0.1.15 → 0.1.16
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 +4 -4
- data/lib/args.rb +1 -1
- data/lib/build_tools/spud/rule.rb +4 -1
- data/lib/build_tools/spud/rule_context.rb +10 -9
- data/lib/shell.rb +5 -1
- data/lib/spud.rb +31 -36
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70f9d7ff9fce7b159e20ad827c5de7edbaa7eded1cb6be6b31359857558a9c24
|
4
|
+
data.tar.gz: c536674d162d71fa1d348f79d365c6b11e4059049d1f9ffc73a4d7b6450c5859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31eadcc43318c65a7be3e88e8e477b0064c0b8b8e7763cf197f29a4ba96323095f0b7ed99770a15ece2a10c568e6caa9a90d1078cc8c165c76d4b5678884ee27
|
7
|
+
data.tar.gz: 9453fe0ceb937c7ed989fb357db0665be4dde3ddf89d809adb969a74064c337ca752beb23fe6a4b17463261dde4415c13d1dca660f390001ba01fadeefed4418
|
data/lib/args.rb
CHANGED
@@ -22,7 +22,7 @@ module Spud
|
|
22
22
|
case arg
|
23
23
|
when '-h', '--help' then [options.merge(help: true), index + 1]
|
24
24
|
when '-v', '--version' then [options.merge(version: true), index + 1]
|
25
|
-
|
25
|
+
when '-w', '--watch' then [options.merge(watches: options[:watches] + [args[index + 1]]), index + 2]
|
26
26
|
when '--debug' then [options.merge(debug: true), index + 1]
|
27
27
|
else raise Error, "invalid option '#{arg}'"
|
28
28
|
end
|
@@ -28,7 +28,10 @@ module Spud::BuildTools
|
|
28
28
|
raise Spud::Error, "invocation of '#{@name}' missing required #{arguments} #{names}"
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
unless key_params?
|
32
|
+
RuleContext.new(@spud, @file_context).instance_exec(*args, &@block)
|
33
|
+
return
|
34
|
+
end
|
32
35
|
|
33
36
|
begin
|
34
37
|
RuleContext.new(@spud, @file_context).instance_exec(*args, **kwargs, &@block)
|
@@ -5,49 +5,50 @@ require_relative '../../error'
|
|
5
5
|
module Spud::BuildTools
|
6
6
|
module SpudBuild
|
7
7
|
class RuleContext
|
8
|
-
attr_reader :__process
|
9
|
-
|
10
8
|
def initialize(spud, file_context)
|
11
9
|
@__spud = spud
|
12
|
-
@__process = nil
|
13
10
|
|
14
11
|
file_context.singleton_methods.each do |method_name|
|
15
12
|
define_singleton_method(method_name, &file_context.method(method_name))
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
16
|
+
def __shell(cmd, silent: false)
|
17
|
+
@__spud.watch_process = Spud::Shell.(cmd, silent: silent, wait: @__spud.wait?)
|
18
|
+
end
|
19
|
+
|
19
20
|
def sh(cmd)
|
20
21
|
out = sh?(cmd)
|
21
|
-
raise ShellError unless out.status.exitstatus.zero?
|
22
|
+
raise ShellError, cmd unless out.status.exitstatus.zero?
|
22
23
|
|
23
24
|
out
|
24
25
|
end
|
25
26
|
|
26
27
|
def sh?(cmd)
|
27
28
|
puts cmd
|
28
|
-
|
29
|
+
__shell(cmd)
|
29
30
|
end
|
30
31
|
|
31
32
|
def shh(cmd)
|
32
33
|
out = shh?(cmd)
|
33
|
-
raise ShellError unless out.status.exitstatus.zero?
|
34
|
+
raise ShellError, cmd unless out.status.exitstatus.zero?
|
34
35
|
|
35
36
|
out
|
36
37
|
end
|
37
38
|
|
38
39
|
def shh?(cmd)
|
39
|
-
|
40
|
+
__shell(cmd)
|
40
41
|
end
|
41
42
|
|
42
43
|
def shhh(cmd)
|
43
44
|
out = shhh?(cmd)
|
44
|
-
raise ShellError,
|
45
|
+
raise ShellError, cmd unless out.status.exitstatus.zero?
|
45
46
|
|
46
47
|
out
|
47
48
|
end
|
48
49
|
|
49
50
|
def shhh?(cmd)
|
50
|
-
|
51
|
+
__shell(cmd, silent: true)
|
51
52
|
end
|
52
53
|
|
53
54
|
def invoke(name, *args, **kwargs)
|
data/lib/shell.rb
CHANGED
@@ -3,7 +3,11 @@ require 'open3'
|
|
3
3
|
|
4
4
|
module Spud
|
5
5
|
class Shell < String
|
6
|
-
def
|
6
|
+
def self.call(cmd, silent: false, wait: false)
|
7
|
+
new(cmd, silent, wait)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(cmd, silent = false, wait = false)
|
7
11
|
output = StringIO.new
|
8
12
|
|
9
13
|
stdin, out, @status = Open3.popen2e(cmd)
|
data/lib/spud.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require_relative 'args'
|
3
3
|
require_relative 'version'
|
4
|
+
require_relative 'shell'
|
4
5
|
require_relative 'build_tools/build_tools'
|
5
6
|
require_relative 'build_tools/spud/shell_error'
|
6
7
|
|
@@ -10,33 +11,39 @@ module Spud
|
|
10
11
|
end
|
11
12
|
|
12
13
|
class Spud
|
14
|
+
attr_accessor :watch_process
|
15
|
+
|
13
16
|
def run!
|
14
|
-
if
|
17
|
+
puts options if debug?
|
18
|
+
puts watches_present: watches_present? if debug?
|
19
|
+
puts wait: wait? if debug?
|
20
|
+
|
21
|
+
if help?
|
15
22
|
print_help!
|
16
23
|
return
|
17
24
|
end
|
18
25
|
|
19
|
-
if
|
26
|
+
if version?
|
20
27
|
puts VERSION
|
21
28
|
return
|
22
29
|
end
|
23
30
|
|
24
|
-
unless
|
31
|
+
unless rule_present?
|
25
32
|
print_rules!
|
26
33
|
return
|
27
34
|
end
|
28
35
|
|
29
|
-
|
36
|
+
if watches_present?
|
30
37
|
watch(options[:watches], rule_name, *args[:positional], **args[:keyword])
|
31
38
|
return
|
32
39
|
end
|
33
40
|
|
34
41
|
invoke(rule_name, *args[:positional], **args[:keyword])
|
35
42
|
rescue BuildTools::SpudBuild::ShellError => e
|
36
|
-
raise e if
|
43
|
+
raise e if debug?
|
37
44
|
|
38
45
|
rescue => e
|
39
|
-
raise e if
|
46
|
+
raise e if debug?
|
40
47
|
puts e.message
|
41
48
|
end
|
42
49
|
|
@@ -62,7 +69,9 @@ module Spud
|
|
62
69
|
if !old_timestamp || new_timestamp > old_timestamp
|
63
70
|
timestamps[filename] = new_timestamp
|
64
71
|
|
72
|
+
watch_process.kill! if watch_process
|
65
73
|
thread.kill if thread
|
74
|
+
|
66
75
|
thread = Thread.new { invoke(name, *args, **kwargs) }
|
67
76
|
break
|
68
77
|
end
|
@@ -71,11 +80,16 @@ module Spud
|
|
71
80
|
sleep 0.1
|
72
81
|
rescue Interrupt
|
73
82
|
thread.kill if thread
|
83
|
+
watch_process.kill! if watch_process
|
74
84
|
break
|
75
85
|
end
|
76
86
|
end
|
77
87
|
end
|
78
88
|
|
89
|
+
def wait?
|
90
|
+
@wait ||= !watches_present?
|
91
|
+
end
|
92
|
+
|
79
93
|
private
|
80
94
|
|
81
95
|
# Rules
|
@@ -91,8 +105,6 @@ module Spud
|
|
91
105
|
end
|
92
106
|
|
93
107
|
def print_rules!
|
94
|
-
#table = rules.map { |name, rule| { name: name, filename: rule.filename } }
|
95
|
-
|
96
108
|
longest_name = 0
|
97
109
|
longest_filename = 0
|
98
110
|
longest_positional = 0
|
@@ -120,34 +132,6 @@ module Spud
|
|
120
132
|
|
121
133
|
puts fields.join(' ')
|
122
134
|
end
|
123
|
-
|
124
|
-
return
|
125
|
-
|
126
|
-
longest_rule = 0
|
127
|
-
longest_filename = 0
|
128
|
-
longest_positional = 0
|
129
|
-
longest_keyword = 0
|
130
|
-
table.each do |(rule, filename)|
|
131
|
-
longest_rule = rule.length if rule.length > longest_rule
|
132
|
-
longest_filename = filename.length if filename.length > longest_filename
|
133
|
-
|
134
|
-
positional = rule.positional_params.map(&method(:wrap_param)).join(' ')
|
135
|
-
longest_positional = positional.length if positional.length > longest_positional
|
136
|
-
|
137
|
-
keyword = rule.keyword_params.map(&method(:prefix_param)).join(' ')
|
138
|
-
longest_keyword = keyword.length if keyword.length > longest_keyword
|
139
|
-
end
|
140
|
-
|
141
|
-
table.each do |(rule, filename)|
|
142
|
-
[
|
143
|
-
[rule, longest_rule],
|
144
|
-
[positional, longest_positional],
|
145
|
-
[filename, longest_filename],
|
146
|
-
[filename, longest_filename],
|
147
|
-
]
|
148
|
-
|
149
|
-
puts "#{rule.ljust(longest_rule)} #{filename.ljust(longest_filename)}"
|
150
|
-
end
|
151
135
|
end
|
152
136
|
|
153
137
|
def wrap_param(name)
|
@@ -176,7 +160,18 @@ module Spud
|
|
176
160
|
puts help.string
|
177
161
|
end
|
178
162
|
|
163
|
+
# Options
|
164
|
+
def watches_present?
|
165
|
+
@watches_present ||= !options[:watches].empty?
|
166
|
+
end
|
167
|
+
|
168
|
+
%i[help version debug].each { |option| define_method("#{option}?") { options[option] } }
|
169
|
+
|
179
170
|
# Args
|
171
|
+
def rule_present?
|
172
|
+
rule_name
|
173
|
+
end
|
174
|
+
|
180
175
|
def options
|
181
176
|
@options ||= args[:options]
|
182
177
|
end
|
data/lib/version.rb
CHANGED