rego 3.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -7
  3. data/bin/rego +81 -14
  4. data/lib/rego/_lib.rb +4 -4
  5. data/rego.gemspec +4 -4
  6. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425e9aeff5786a7815c4647b7e3370d392b6d298a2b0ed210366b80bff7b5a8f
4
- data.tar.gz: 3b43f2b8b22ad22dd1ae9df75992af8104cfde581e3ccae148f164eb50f62bd5
3
+ metadata.gz: 5937ded18cabcdb05d4f5dbe275d259c7745d5c112056a72cbc97fc7484c2ef6
4
+ data.tar.gz: fe4409461089289456b7c6e1f9334424f76c0c27985698e0ec7e70f340d42ed2
5
5
  SHA512:
6
- metadata.gz: 1bc5fdb63f78606d066b65644564b02dd760c9bfba83a79e21d272b656bdacc78e53fa306c75b577d0d21c229afaa8a96a737b407b32b233fc02a2d118f5ef70
7
- data.tar.gz: fadcef5875b4a2ca0fae127458f4df2090ab029afad31d06e32cc73d039b4cf1e32931dc71fd0a2df2606c2d1e4c405c252fe19e2565f5d8c1ecf342b1b1acf2
6
+ metadata.gz: c31ab16a824f9fa83c3adf05aee70ba6e138a6b5e3a50a8da7e0714fe9d04fb340653315926a4d0cf086725510a3dca142502c8874902da7a14f18d87d72e90c
7
+ data.tar.gz: 54302f9c2a46e7691d626cf83abac7eb7789e10457df67dd189bcc0c6cc6c07eb03b5b660a2817d504c28cc92de325624a1203cf7f3dbd653bfa082e59a86358
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  NAME
2
2
  ---------------
3
-
3
+
4
4
  rego
5
5
 
6
6
  SYNOPSIS
7
7
  ---------------
8
-
8
+
9
9
  rego ./files ./to ./watch -- command-to-run
10
10
 
11
11
  INSTALL
@@ -15,28 +15,28 @@ gem install rego
15
15
 
16
16
  DESCRIPTION
17
17
  ---------------
18
-
18
+
19
19
  run arbitrary commands easily when files change
20
20
 
21
21
  PARAMETERS
22
22
  ---------------
23
23
 
24
- --help, -h
24
+ --help, -h
25
25
 
26
26
  EXAMPLES
27
27
  ---------------
28
-
28
+
29
29
  ```bash
30
30
 
31
31
  # say hai whenever the file foo.txt changes
32
32
  #
33
33
  ~> rego foo.txt -- echo hai
34
34
 
35
- # say hai whenever any file (recursively) in bar changes
35
+ # say hai whenever any file (recursively) in bar changes
36
36
  #
37
37
  ~> rego ./bar/ -- echo hai
38
38
 
39
- # echo *the file that changed* when any file (recursively) in bar changes
39
+ # echo *the file that changed* when any file (recursively) in bar changes
40
40
  #
41
41
  ~> rego ./bar/ -- echo "@ was changed"
42
42
 
@@ -48,4 +48,8 @@ EXAMPLES
48
48
  #
49
49
  ~> rego ./test -- ruby -Itest @
50
50
 
51
+ # run a server, killing it gracefully whenever files change
52
+ #
53
+ ~> rego --killer -- ./dev/server
54
+
51
55
  ```
data/bin/rego CHANGED
@@ -29,12 +29,18 @@ Main do
29
29
  # run a specific test whenever it, or your app, has changed
30
30
  #
31
31
  ~> rego ./test -- ruby -Itest @
32
+
33
+ # run a server, killing it gracefully whenever files change
34
+ #
35
+ ~> rego --killer -- ./dev/server
32
36
  __
33
37
 
34
38
  option('--path=path', '-p')
35
39
  option('--paths=paths')
36
40
  option('--command=command', '-c')
37
41
  option('--version', '-v')
42
+ option('--killer', '-k')
43
+ option('--retry', '-r')
38
44
 
39
45
  def run
40
46
  if params[:version].given?
@@ -86,35 +92,96 @@ Main do
86
92
  end
87
93
 
88
94
  def loop_watching_files_and_running_commands!
89
- cmdno = '0'
95
+ @cmdno = '0'
96
+ @killer = params[:killer].given?
97
+ @retry = params[:retry].given?
98
+ @pid = nil
99
+ @killed = false
90
100
 
91
101
  rego =
92
102
  proc do
93
- puts
94
- Rego.say("#=> rego.#{cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{@pretty[:command]}", color: :yellow)
103
+ loop do
104
+ puts
105
+ Rego.say("#=> rego.#{@cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{@pretty[:command]}", color: :yellow)
106
+
107
+ @killed = false
108
+ @pid = Process.spawn(*@command)
109
+ Rego.say("#=> rego.#{@cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> pid=#{@pid}", color: :cyan)
110
+ status = Process.wait(@pid)
111
+ @pid = nil
112
+
113
+ success = (@killer || (status==0))
114
+
115
+ puts
116
+ Rego.say("#=> rego.#{@cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{status}", color: (success ? :green : :red))
117
+
118
+ @cmdno.succ!
119
+ puts
120
+
121
+ if @retry and not @killed
122
+ puts 'retrying...'
123
+ sleep(rand)
124
+ puts '...'
125
+ else
126
+ break
127
+ end
128
+ end
95
129
 
96
- success = system(*@command)
97
- puts
130
+ status
131
+ end
98
132
 
99
- Rego.say("#=> rego.#{cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> #{$?.exitstatus}",
100
- color: (success ? :green : :red))
101
- puts
133
+ listener =
134
+ Listen.to(*@paths) do |_modified, _added, _removed|
135
+ if @killer && @pid
136
+ @killed = kill!(@pid)
137
+ end
102
138
 
103
- cmdno.succ!
139
+ rego.call unless @retry
104
140
  end
105
141
 
106
- listener = Listen.to(*@paths) do |_modified, _added, _removed|
107
- rego.call
108
- end
109
-
110
142
  begin
111
- rego.call
112
143
  listener.start
144
+ rego.call
113
145
  sleep
114
146
  rescue SignalException
115
147
  exit(0)
116
148
  end
117
149
  end
150
+
151
+ def kill!(pid)
152
+ Rego.say("#=> rego.#{@cmdno} @ #{Time.now.strftime('%H:%M:%S')} -> kill=#{@pid}", color: :magenta)
153
+
154
+ 3.times do
155
+ %w[
156
+ SIGTERM SIGINT SIGQUIT SIGKILL
157
+ ].each do |signal|
158
+ begin
159
+ Process.kill("-#{signal}", pid)
160
+ rescue Object
161
+ nil
162
+ end
163
+
164
+ sleep(0.1)
165
+
166
+ return pid if alive?(pid)
167
+
168
+ sleep(rand)
169
+ end
170
+ end
171
+
172
+ abort("failed to kill pid=#{ pid }!") if alive?(pid)
173
+
174
+ pid
175
+ end
176
+
177
+ def alive?(pid)
178
+ begin
179
+ Process.kill(0, pid)
180
+ true
181
+ rescue Errno::ESRCH
182
+ false
183
+ end
184
+ end
118
185
  end
119
186
 
120
187
  BEGIN {
data/lib/rego/_lib.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Rego
2
- Version = '3.2.1' unless defined?(Version)
2
+ Version = '4.2.2' unless defined?(Version)
3
3
 
4
4
  def self.version
5
5
  Rego::Version
@@ -7,9 +7,9 @@ module Rego
7
7
 
8
8
  def self.dependencies
9
9
  {
10
- 'main' => ['main', ' ~> 6.3.0'],
11
- 'map' => ['map', ' ~> 6.6.0'],
12
- 'listen' => ['listen', ' ~> 3.8.0']
10
+ 'main' => ['main', ' ~> 6'],
11
+ 'map' => ['map', ' ~> 6'],
12
+ 'listen' => ['listen', ' ~> 3.9']
13
13
  }
14
14
  end
15
15
 
data/rego.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "rego"
6
- spec.version = "3.2.1"
6
+ spec.version = "4.2.2"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "rego"
9
9
  spec.description = "description: rego kicks the ass"
@@ -18,11 +18,11 @@ Gem::Specification::new do |spec|
18
18
  spec.test_files = nil
19
19
 
20
20
 
21
- spec.add_dependency(*["main", " ~> 6.3.0"])
21
+ spec.add_dependency(*["main", " ~> 6"])
22
22
 
23
- spec.add_dependency(*["map", " ~> 6.6.0"])
23
+ spec.add_dependency(*["map", " ~> 6"])
24
24
 
25
- spec.add_dependency(*["listen", " ~> 3.8.0"])
25
+ spec.add_dependency(*["listen", " ~> 3.9"])
26
26
 
27
27
 
28
28
  spec.extensions.push(*[])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rego
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: main
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.3.0
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.3.0
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: map
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.6.0
33
+ version: '6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.6.0
40
+ version: '6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: listen
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.8.0
47
+ version: '3.9'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.8.0
54
+ version: '3.9'
55
55
  description: 'description: rego kicks the ass'
56
56
  email: ara.t.howard@gmail.com
57
57
  executables:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.4.1
88
+ rubygems_version: 3.5.16
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: rego