raykit 0.0.322 → 0.0.323

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: 2b6a6dfaef888511950ae3963bd45ba6fa75136319984315e875f8e4cf79172f
4
- data.tar.gz: b28f6c77327b17b2f61f889fb4148e03063d3b9b201559a4f8396e98068713cb
3
+ metadata.gz: efd74944a1f30ac6317bef794cc964e37e484cef50814f0702b61b7b17c1d4d2
4
+ data.tar.gz: 5eb12a1cafeb1dd6812d5747ea90046face2dfefffdc4c6008ec7d4593d26a4a
5
5
  SHA512:
6
- metadata.gz: f9cac9bbfe5f7f118b7fde0133e0d3c4a458a25a87dbb235c53c2201675221c45f71c8ea108d281ece5b59242ea632f5faebdf1f4bc34f184dfd5dc80723458e
7
- data.tar.gz: 4d4a92abc1d5dca663b2368d33034ac12030a4024887b89c5015243f10cdfb0cc8a2f64d6537236114f2bb7f1da74591478d744bb9202c368b80526f99d3f3ef
6
+ metadata.gz: 4848c9952dcc2853067c1e7ef54b275f1c08c4dd18dac99c5e692750bc2ce28d526bd7e74da7910e27577ae1251f2ba20fe0f6510c51a7ab5ea140a58722a8b0
7
+ data.tar.gz: 8390ef4a06b1c5c48217dda4e729647750757e03c15e3a0a4ebc5c90c9dfae214f9422aedc329f5346b39903ad27986dec94f6c0311877b7645f0d0ddc52fffa
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "open3"
4
2
  require "timeout"
5
3
  require "json"
@@ -26,39 +24,51 @@ module Raykit
26
24
  def init_defaults
27
25
  @timeout = 0
28
26
  @directory = Dir.pwd
29
- @output = ""
30
- @error = ""
27
+ @output = +""
28
+ @error = +""
31
29
  @exitstatus = 0
32
30
  @user = Environment.user
33
31
  @machine = Environment.machine
34
32
  @logging_enabled = true
35
33
  end
36
34
 
37
- def initialize(command, timeout = 0, success_log_level = Logger::DEBUG, logging_enabled = true)
35
+ def initialize(command)
36
+ #def initialize(command, timeout = 0, success_log_level = Logger::DEBUG, logging_enabled = true)
37
+ timeout = 0
38
+ success_log_level = nil
39
+ logging_enabled = false
38
40
  @@commands = []
39
41
  init_defaults
40
42
  @success_log_level = success_log_level
41
43
  @logging_enabled = logging_enabled
42
44
  @command = command
43
45
  @timeout = timeout
44
- run if @command.length.positive?
46
+ #t = Time.now
47
+ @elapsed = 0
48
+ #run if @command.length.positive?
49
+ self
50
+ end
51
+
52
+ def set_timeout(timeout)
53
+ @timeout = timeout
45
54
  self
46
55
  end
47
56
 
48
57
  def run
49
58
  # puts '---running---'
50
59
  @start_time = Time.now
60
+ @elapsed = 0
51
61
  timer = Timer.new
52
62
  if @timeout.zero?
53
63
  @output, @error, process_status = Open3.capture3(@command)
54
64
  @exitstatus = process_status.exitstatus
55
65
  else
66
+ puts "@timeout is #{@timeout}"
56
67
  Open3.popen3(@command, chdir: @directory) do |_stdin, stdout, stderr, thread|
57
- tick = 2
68
+ tick = 1
58
69
  pid = thread.pid
59
70
  start = Time.now
60
- elapsed = Time.now - start
61
- while ((elapsed) < @timeout) && thread.alive?
71
+ while ((Time.now - start) < @timeout) && thread.alive?
62
72
  Kernel.select([stdout, stderr], nil, nil, tick)
63
73
  begin
64
74
  @output << stdout.read_nonblock(BUFFER_SIZE)
@@ -68,8 +78,8 @@ module Raykit
68
78
  @exitstatus = thread.value.exitstatus
69
79
  break
70
80
  end
71
- elapsed = Time.now - start
72
81
  end
82
+ sleep 1
73
83
  if thread.alive?
74
84
  if Gem.win_platform?
75
85
  `taskkill /f /pid #{pid}`
@@ -77,7 +87,7 @@ module Raykit
77
87
  Process.kill("TERM", pid)
78
88
  end
79
89
  @exitstatus = 5
80
- @error = "timed out"
90
+ @error = +"timed out"
81
91
  else
82
92
  @exitstatus = thread.value.exitstatus
83
93
  end
@@ -100,8 +110,10 @@ module Raykit
100
110
  end
101
111
  end
102
112
  end
113
+ self
103
114
  end
104
115
 
116
+
105
117
  def to_log_event
106
118
  secrets = Secrets.new
107
119
  msg = secrets.hide(@command)
@@ -168,25 +180,35 @@ module Raykit
168
180
  "#{format("%.0f", elapsed)}s"
169
181
  end
170
182
 
171
- def summary(show_directory = false)
183
+ def summary(show_directory = true)
172
184
  checkmark = "\u2713"
173
185
  # warning="\u26A0"
174
186
  error = "\u0058"
175
187
  symbol = Rainbow(checkmark.encode("utf-8")).green
176
188
  symbol = Rainbow(error.encode("utf-8")).red if @exitstatus != 0
177
189
  if show_directory
178
- puts "#{symbol} #{elapsed_str.rjust(4)} #{Rainbow(SECRETS.hide(@command)).yellow} (#{@directory})"
190
+ puts "#{symbol} #{Rainbow(SECRETS.hide(@command)).yellow} (#{@directory},#{elapsed_str})"
179
191
  else
180
- puts "#{symbol} #{elapsed_str.rjust(4)} #{Rainbow(SECRETS.hide(@command)).yellow}" # + " (#{@directory})"
192
+ puts "#{symbol} #{Rainbow(SECRETS.hide(@command)).yellow} (#{elapsed_str})"
181
193
  end
182
- # puts symbol + " " + elapsed_str.rjust(4) + " " + Rainbow(SECRETS.hide(@command)).yellow# + " (#{@directory})"
194
+ self
183
195
  end
184
196
 
185
197
  def details
198
+ if @output.length > 0
199
+ @output.lines.each do |line|
200
+ puts ' ' + line
201
+ end
202
+ end
203
+ if @error.length > 0
204
+ @error.lines.each do |line|
205
+ puts ' ' + line
206
+ end
207
+ end
186
208
  # summary
187
- puts @output
188
- puts @error
189
- puts
209
+ #puts @output
210
+ #puts @error
211
+ #puts
190
212
  end
191
213
 
192
214
  def save
@@ -87,7 +87,7 @@ module Raykit
87
87
  end
88
88
 
89
89
  def get_tag_commit_id(name)
90
- cmd = Raykit::Command.new("git rev-parse \"#{name}\"", 0, nil, false)
90
+ cmd = Raykit::Command.new("git rev-parse \"#{name}\"").run#, 0, nil, false)
91
91
  if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
92
92
  cmd.output.strip
93
93
  else
@@ -97,7 +97,7 @@ module Raykit
97
97
 
98
98
  def has_tag(name)
99
99
  cmd = Raykit::Command.new("git rev-parse \"#{name}\"", 0, nil, false)
100
- if !cmd.output.include?('fatal') && !cmd.error.include?('fatal')
100
+ if !cmd.output.include?("fatal") && !cmd.error.include?("fatal")
101
101
  true
102
102
  else
103
103
  false
@@ -144,7 +144,7 @@ module Raykit
144
144
  def remote
145
145
  if Dir.exist?(directory)
146
146
  Dir.chdir(directory) do
147
- return Command.new("git config --get remote.origin.url").output.strip if Dir.exist?(".git")
147
+ return Command.new("git config --get remote.origin.url").run.output.strip if Dir.exist?(".git")
148
148
  end
149
149
  end
150
150
  ""
data/lib/raykit/log.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "json"
4
2
 
5
3
  module Raykit
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake/clean'
4
- require 'digest'
3
+ require "rake/clean"
4
+ require "digest"
5
5
  RAKE_DIRECTORY = Rake.application.original_dir
6
+
6
7
  module Raykit
7
8
  class Project
8
9
  attr_accessor :name, :timer, :verbose, :target
@@ -19,8 +20,8 @@ module Raykit
19
20
  def initialize
20
21
  @verbose = false
21
22
  @timer = Raykit::Timer.new
22
- @remote = ''
23
- @commit_message_filename = 'commit_message.tmp'
23
+ @remote = ""
24
+ @commit_message_filename = "commit_message.tmp"
24
25
  if Dir.exist?(RAKE_DIRECTORY)
25
26
  @directory = RAKE_DIRECTORY
26
27
  if Dir.exist?("#{RAKE_DIRECTORY}/.git") && Dir.exist?(@directory)
@@ -28,7 +29,7 @@ module Raykit
28
29
  @remote = @git_directory.remote
29
30
  end
30
31
  else
31
- @directory = ''
32
+ @directory = ""
32
33
  end
33
34
 
34
35
  # @log=Log.new("#{RAKE_DIRECTORY}/tmp/raykit.log")
@@ -36,16 +37,16 @@ module Raykit
36
37
  if defined?(NAME)
37
38
  @name = NAME
38
39
  else
39
- slns = Dir.glob('*.sln')
40
+ slns = Dir.glob("*.sln")
40
41
  if slns.length == 1
41
- @name = slns[0].gsub('.sln', '')
42
+ @name = slns[0].gsub(".sln", "")
42
43
  else
43
- gemspecs = Dir.glob('*.gemspec')
44
+ gemspecs = Dir.glob("*.gemspec")
44
45
  if gemspecs.length == 1
45
- @name = gemspecs[0].gsub('.gemspec', '')
46
+ @name = gemspecs[0].gsub(".gemspec", "")
46
47
  else
47
- remote_parts = @remote.split('/')
48
- @name = remote_parts[-1].gsub('.git', '') if remote_parts.length.positive?
48
+ remote_parts = @remote.split("/")
49
+ @name = remote_parts[-1].gsub(".git", "") if remote_parts.length.positive?
49
50
  end
50
51
  end
51
52
  end
@@ -64,7 +65,7 @@ module Raykit
64
65
  def target_md5
65
66
  return Digest::MD5.file(target).to_s.strip if !target.nil? && File.exist?(target)
66
67
 
67
- ''
68
+ ""
68
69
  end
69
70
 
70
71
  def branch
@@ -84,7 +85,7 @@ module Raykit
84
85
 
85
86
  def outstanding_commit?
86
87
  Dir.chdir(@directory) do
87
- return true unless `git status`.include?('nothing to commit')
88
+ return true unless `git status`.include?("nothing to commit")
88
89
  end
89
90
  false
90
91
  end
@@ -93,7 +94,7 @@ module Raykit
93
94
  # puts `git log -n 1`
94
95
  # !latest_tag_commit.eql?(latest_commit)
95
96
  # commit 2e4cb6d6c0721e16cd06afee85b7cdc27354921b (HEAD -> master, tag: 0.0.180, origin/master, origin/HEAD)
96
- outstanding_commit? || !`git log -n 1`.include?('tag:')
97
+ outstanding_commit? || !`git log -n 1`.include?("tag:")
97
98
  end
98
99
 
99
100
  def detached?
@@ -101,8 +102,6 @@ module Raykit
101
102
  @git_directory.detached?
102
103
  end
103
104
 
104
-
105
-
106
105
  def has_diff?(filename)
107
106
  Dir.chdir(@directory) do
108
107
  text = `git diff #{filename}`.strip
@@ -141,12 +140,12 @@ module Raykit
141
140
  scan = text.scan(/md5=(\w{32})/)
142
141
  return scan[0][0].to_s.strip if scan.length.positive? && scan[0].length.positive?
143
142
 
144
- ''
143
+ ""
145
144
  end
146
145
 
147
146
  def last_modified_filename
148
147
  Dir.chdir(@directory) do
149
- Dir.glob('**/*.*').select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
148
+ Dir.glob("**/*.*").select { |f| File.file?(f) }.max_by { |f| File.mtime(f) }
150
149
  end
151
150
  end
152
151
 
@@ -175,33 +174,33 @@ module Raykit
175
174
  def elapsed
176
175
  elapsed = @timer.elapsed
177
176
  if elapsed < 1.0
178
- "#{format('%.1f', @timer.elapsed)}s"
177
+ "#{format("%.1f", @timer.elapsed)}s"
179
178
  else
180
- "#{format('%.0f', @timer.elapsed)}s"
179
+ "#{format("%.0f", @timer.elapsed)}s"
181
180
  end
182
181
  end
183
182
 
184
183
  def info
185
184
  ljust = 35
186
- puts ''
187
- puts 'PROJECT.name'.ljust(ljust) + Rainbow(PROJECT.name).yellow.bright
188
- puts 'PROJECT.version'.ljust(ljust) + Rainbow(PROJECT.version).yellow.bright
189
- puts 'PROJECT.remote'.ljust(ljust) + Rainbow(PROJECT.remote).yellow.bright
190
- puts 'PROJECT.branch'.ljust(ljust) + Rainbow(PROJECT.branch).yellow.bright
191
- puts 'PROJECT.detached?'.ljust(ljust) + Rainbow(PROJECT.detached?).yellow.bright
185
+ puts ""
186
+ puts "PROJECT.name".ljust(ljust) + Rainbow(PROJECT.name).yellow.bright
187
+ puts "PROJECT.version".ljust(ljust) + Rainbow(PROJECT.version).yellow.bright
188
+ puts "PROJECT.remote".ljust(ljust) + Rainbow(PROJECT.remote).yellow.bright
189
+ puts "PROJECT.branch".ljust(ljust) + Rainbow(PROJECT.branch).yellow.bright
190
+ puts "PROJECT.detached?".ljust(ljust) + Rainbow(PROJECT.detached?).yellow.bright
192
191
  # puts "PROJECT.target".ljust(ljust) + Rainbow(PROJECT.target).yellow.bright
193
192
  # puts "PROJECT.target_md5".ljust(ljust) + Rainbow(PROJECT.target_md5).yellow.bright
194
- puts 'PROJECT.latest_tag'.ljust(ljust) + Rainbow(PROJECT.latest_tag).yellow.bright
195
- puts 'PROJECT.latest_tag_commit'.ljust(ljust) + Rainbow(PROJECT.latest_tag_commit).yellow.bright
196
- puts 'PROJECT.latest_tag_md5'.ljust(ljust) + Rainbow(PROJECT.latest_tag_md5).yellow.bright
197
- puts 'PROJECT.latest_commit'.ljust(ljust) + Rainbow(PROJECT.latest_commit).yellow.bright
198
- puts 'PROJECT.last_modified_filename'.ljust(ljust) + Rainbow(PROJECT.last_modified_filename).yellow.bright
193
+ puts "PROJECT.latest_tag".ljust(ljust) + Rainbow(PROJECT.latest_tag).yellow.bright
194
+ puts "PROJECT.latest_tag_commit".ljust(ljust) + Rainbow(PROJECT.latest_tag_commit).yellow.bright
195
+ puts "PROJECT.latest_tag_md5".ljust(ljust) + Rainbow(PROJECT.latest_tag_md5).yellow.bright
196
+ puts "PROJECT.latest_commit".ljust(ljust) + Rainbow(PROJECT.latest_commit).yellow.bright
197
+ puts "PROJECT.last_modified_filename".ljust(ljust) + Rainbow(PROJECT.last_modified_filename).yellow.bright
199
198
  # puts "PROJECT.elapsed".ljust(ljust) + Rainbow(PROJECT.elapsed).yellow.bright
200
- puts 'PROJECT.size'.ljust(ljust) + Rainbow(PROJECT.size).yellow.bright
201
- puts 'PROJECT.size_pack'.ljust(ljust) + Rainbow(PROJECT.size_pack).yellow.bright
202
- puts 'PROJECT.outstanding_commit?'.ljust(ljust) + Rainbow(PROJECT.outstanding_commit?).yellow.bright
203
- puts 'PROJECT.outstanding_tag?'.ljust(ljust) + Rainbow(PROJECT.outstanding_tag?).yellow.bright
204
- puts ''
199
+ puts "PROJECT.size".ljust(ljust) + Rainbow(PROJECT.size).yellow.bright
200
+ puts "PROJECT.size_pack".ljust(ljust) + Rainbow(PROJECT.size_pack).yellow.bright
201
+ puts "PROJECT.outstanding_commit?".ljust(ljust) + Rainbow(PROJECT.outstanding_commit?).yellow.bright
202
+ puts "PROJECT.outstanding_tag?".ljust(ljust) + Rainbow(PROJECT.outstanding_tag?).yellow.bright
203
+ puts ""
205
204
  self
206
205
  end
207
206
 
@@ -219,10 +218,10 @@ module Raykit
219
218
  def commit(commit_message)
220
219
  warn "[DEPRECATION] 'commit_message_filename' is deprectated. Use a run command for better transparency."
221
220
  Dir.chdir(@directory) do
222
- if File.exist?('.gitignore')
221
+ if File.exist?(".gitignore")
223
222
  status = `git status`
224
- if status.include?('Changes not staged for commit:')
225
- run('git add --all')
223
+ if status.include?("Changes not staged for commit:")
224
+ run("git add --all")
226
225
  if GIT_DIRECTORY.outstanding_commit?
227
226
  if File.exist?(@commit_message_filename)
228
227
  run("git commit --file #{@commit_message_filename}")
@@ -233,7 +232,7 @@ module Raykit
233
232
  end
234
233
  end
235
234
  else
236
- puts 'warning: .gitignore not found.'
235
+ puts "warning: .gitignore not found."
237
236
  end
238
237
  end
239
238
  self
@@ -243,9 +242,7 @@ module Raykit
243
242
  Dir.chdir(@directory) do
244
243
  status = `git status`
245
244
  if status.include?('use "git push"')
246
- run('git push')
247
-
248
- # run('git push --tags')
245
+ run("git push")
249
246
  end
250
247
  end
251
248
  self
@@ -253,7 +250,7 @@ module Raykit
253
250
 
254
251
  def pull
255
252
  Dir.chdir(@directory) do
256
- run('git pull')
253
+ run("git pull")
257
254
  end
258
255
  self
259
256
  end
@@ -280,17 +277,15 @@ module Raykit
280
277
  self
281
278
  end
282
279
 
283
- def run(command, quit_on_failure = true, success_log_level = Logger::DEBUG)
280
+ def run(command, quit_on_failure = true)
284
281
  if command.is_a?(Array)
285
282
  command.each { |subcommand| run(subcommand, quit_on_failure, success_log_level) }
286
283
  else
287
- cmd = Command.new(command, 0, success_log_level)
284
+ cmd = Command.new(command).set_timeout(0).run
288
285
  cmd.summary
289
286
  cmd.save
290
287
  elapsed_str = Timer.get_elapsed_str(cmd.elapsed, 0)
291
288
  if !cmd.exitstatus.nil? && cmd.exitstatus.zero?
292
- # puts elapsed_str + " " + Rainbow(cmd.command).yellow.bright
293
- # return elapsed_str + " " + cmd.command
294
289
  else
295
290
  # display error details
296
291
  puts cmd.output
data/lib/raykit/tasks.rb CHANGED
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  desc "integrate changes into the git repository"
9
9
  task :integrate do
10
- puts Rainbow(":integrate").blue.bright
10
+ puts Rainbow(": integrate").blue.bright
11
11
 
12
12
  git_dir = Raykit::Git::Directory.new(Rake.application.original_dir)
13
13
  if git_dir.detached?
@@ -16,7 +16,7 @@ task :integrate do
16
16
  if PROJECT.outstanding_commit?
17
17
  Rake::Task["test"].invoke if Rake::Task.task_defined?("test")
18
18
  else
19
- puts "no outstanding commits detected"
19
+ puts " no outstanding commits detected"
20
20
  end
21
21
 
22
22
  if !File.exist?(".gitignore")
@@ -48,7 +48,7 @@ end
48
48
 
49
49
  desc "clean files not tracked by git"
50
50
  task :clean do
51
- puts Rainbow(":clean").blue.bright
51
+ puts Rainbow(": clean").blue.bright
52
52
  PROJECT.run("git clean -dXf")
53
53
  end
54
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raykit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.322
4
+ version: 0.0.323
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-27 00:00:00.000000000 Z
11
+ date: 2021-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler