raykit 0.0.500 → 0.0.501

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b2a3e1c22735ebdacb0d6e65529afda2553beb7e3035c015b894523ec839fc3
4
- data.tar.gz: a70d5d46c87f1eb517020af2e59f0e3efd3fde472d9aed2a6d9d63be769680a9
3
+ metadata.gz: 030637eb6f5b006e96bdc07f68426d12e5c3e847681f9ce8d92f7579cc81ffd8
4
+ data.tar.gz: a1eae5cf64d7ce6f2a30e56bc0b01b341c882dfd2820020218814ad2aa6546a0
5
5
  SHA512:
6
- metadata.gz: d5062b8fff78d1a0c5321afa51f6171cff9aa77e344dbbf6be70119d2ba502934156c671600dc4ca526ba2962d19f14d75331fb13c8ddb7d283877cb58ebcbe8
7
- data.tar.gz: 7713d9d0f5a112b570ed6eee588e8d491ed9a075ea7747ea5a8695d24c115233fccbfdd88341748134b898848c8490d76892c5e2f4892327959cb21dbbf58e56
6
+ metadata.gz: eaecd3d17476fdfcdec18204073c711c409446dd90f18f9739c6b8bcd0386eaba2da0f2fbf88ff86f7f2ab72c00200e259312f1606007052159daaa6da8e3b0e
7
+ data.tar.gz: 55b7481f38dc0ee2d687af3165e81b90dbd1309d94e291a30ee46e490906f82acf34a52ce67df7d8e5ba8c0a4df57b172789b827b635f5b2f596f94681892d64
@@ -203,11 +203,13 @@ module Raykit
203
203
  end
204
204
 
205
205
  def summary(show_directory = false)
206
- checkmark = "\u2713"
206
+ #checkmark = "\u2713"
207
207
  # warning="\u26A0"
208
- error = "\u0058"
209
- symbol = Rainbow(checkmark.encode("utf-8")).green
210
- symbol = Rainbow(error.encode("utf-8")).red if @exitstatus != 0
208
+ #error = "\u0058"
209
+ #symbol = Rainbow(checkmark.encode("utf-8")).green
210
+ #symbol = Rainbow(error.encode("utf-8")).red if @exitstatus != 0
211
+ symbol = Raykit::Symbols::checkmark if @exitstatus.zero?
212
+ symbol = Raykit::Symbols::error if @exitstatus != 0
211
213
  cmd = "#{Rainbow(SECRETS.hide(@command)).yellow}"
212
214
  if show_directory
213
215
  puts "#{symbol} #{cmd} " + Rainbow("#{elapsed_str}").cyan
@@ -9,18 +9,32 @@ module Raykit
9
9
  class Console
10
10
  attr_accessor :opts
11
11
 
12
- def initialize
13
- @opts = Slop.parse do |o|
12
+ def self.get_opts
13
+ Slop.parse do |o|
14
14
  o.string "-t", "--task", "rake task", default: "default"
15
15
  o.bool "-v", "--verbose", "print detailed output", default: false
16
16
  o.bool "-q", "--quiet", "minimal output", default: false
17
17
  o.bool "-s", "--stop", "stop on error", default: true
18
18
  end
19
+ end # def self.get_opts
19
20
 
20
- if opts.verbose?
21
- puts "options: #{Rainbow(@opts.to_hash).yellow.bright}"
22
- puts "arguments:#{Rainbow(@opts.arguments).yellow.bright}"
21
+ def initialize(opts = nil)
22
+ if opts.nil?
23
+ @opts = Console.get_opts
24
+ else
25
+ @opts = opts
23
26
  end
27
+ #@opts = Slop.parse do |o|
28
+ # o.string "-t", "--task", "rake task", default: "default"
29
+ # o.bool "-v", "--verbose", "print detailed output", default: false
30
+ # o.bool "-q", "--quiet", "minimal output", default: false
31
+ # o.bool "-s", "--stop", "stop on error", default: true
32
+ #end
33
+
34
+ #if opts.verbose?
35
+ # puts "options: #{Rainbow(@opts.to_hash).yellow.bright}"
36
+ # puts "arguments:#{Rainbow(@opts.arguments).yellow.bright}"
37
+ #end
24
38
  end
25
39
 
26
40
  def run
@@ -33,6 +47,8 @@ module Raykit
33
47
  add
34
48
  when "remove"
35
49
  remove
50
+ when "list"
51
+ list
36
52
  when "show"
37
53
  show
38
54
  when "work"
@@ -56,6 +72,7 @@ module Raykit
56
72
  def verb_descriptions
57
73
  { "add" => "add a git url",
58
74
  "remove" => "remove one or more git urls",
75
+ "list" => "list summaries of repositories",
59
76
  "show" => "show git urls matching a specific pattern",
60
77
  "work" => "clone and rake a git repository",
61
78
  "import" => "import git urls matching a specific pattern",
@@ -121,6 +138,16 @@ module Raykit
121
138
  end
122
139
  end
123
140
 
141
+ def list
142
+ pattern = ""
143
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
144
+ REPOSITORIES.matches(pattern).each do |url|
145
+ repo = Raykit::Git::Repository.new(url)
146
+ puts repo.to_s
147
+ #puts url
148
+ end
149
+ end
150
+
124
151
  def show
125
152
  pattern = ""
126
153
  pattern = @opts.arguments[1] if @opts.arguments.length > 1
@@ -154,7 +181,7 @@ module Raykit
154
181
  #puts cmd.to_s
155
182
 
156
183
  def work_url(url)
157
- return 0 if url == "https://gitlab.com/lou-parslow/raykit.git"
184
+ return 0 if url == "https://gitlab.com/gems-rb/raykit.git"
158
185
 
159
186
  puts Rainbow(url).yellow.bright if @opts.verbose?
160
187
  repo = Raykit::Git::Repository.new(url)
@@ -6,7 +6,7 @@ module Raykit
6
6
  # Functionality to manage a remote git repository
7
7
  class Repository
8
8
  # The url of the remote repository
9
- attr_accessor :url
9
+ attr_accessor :url, :latest_commit_id, :latest_commit_exit_status
10
10
  attr_accessor :clone_directory, :work_directory
11
11
 
12
12
  def initialize(url)
@@ -16,6 +16,41 @@ module Raykit
16
16
  @url = url
17
17
  @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone"))
18
18
  @work_directory = Raykit::Git::Directory.new(get_dev_dir("work"))
19
+ load
20
+ end
21
+
22
+ def filename
23
+ Environment.get_dev_dir("data") + File::SEPARATOR + "repository" + File::SEPARATOR + Raykit::FileSystem::replace_invalid_chars(relative_path.gsub("/", ".").gsub("\\", ".")) + ".json"
24
+ end
25
+
26
+ def save
27
+ # Create the config directory if it doesn't exist.
28
+ dir = File.dirname(filename)
29
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
30
+
31
+ File.write(filename, {
32
+ latest_commit_id: @latest_commit_id,
33
+ latest_commit_exit_status: @latest_commit_exit_status,
34
+ }.to_json)
35
+ end
36
+
37
+ def load
38
+ if (File.exist?(filename))
39
+ data = JSON.parse(File.read(filename))
40
+ @latest_commit_id = data["latest_commit_id"]
41
+ @latest_commit_exit_status = data["latest_commit_exit_status"]
42
+ end
43
+ end
44
+
45
+ def update
46
+ @latest_commit_id = latest_commit(default_branch)
47
+ if (@latest_commit_id.nil? || @latest_commit_id.empty?)
48
+ cmd = get_make_command(@latest_commit_id, "rake default")
49
+ if (!cmd.nil?)
50
+ @latest_commit_exit_status = cmd.exitstatus
51
+ end
52
+ end
53
+ save
19
54
  end
20
55
 
21
56
  def short_name()
@@ -117,6 +152,18 @@ module Raykit
117
152
  ""
118
153
  end
119
154
 
155
+ def latest_commit_date(branch)
156
+ if checkout_local_clone_directory_branch(branch)
157
+ update_local_clone_directory
158
+ Dir.chdir(local_clone_directory) do
159
+ text = `git log -n 1`
160
+ scan = text.scan(/Date:\s+(.*)/)
161
+ return scan[0][0].to_s
162
+ end # Dir.chdir
163
+ end # if checkout_local_clone_directory_branch
164
+ ""
165
+ end
166
+
120
167
  # The latest tag for a branch of the repository
121
168
  def latest_tag(branch)
122
169
  return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
@@ -125,7 +172,7 @@ module Raykit
125
172
  end
126
173
 
127
174
  private def local_clone_directory
128
- clone_dir = "#{Environment.get_dev_dir("clone")}/#{relative_path}"
175
+ clone_dir = Environment::normalize_path("#{Environment.get_dev_dir("clone")}/#{relative_path}")
129
176
  end
130
177
 
131
178
  public def update_local_clone_directory
@@ -170,12 +217,15 @@ module Raykit
170
217
  end
171
218
 
172
219
  def pull
220
+ #repo = Raykit::Git::Repository.new(url)
221
+ #work_dir = repo.get_dev_dir("work")
222
+ #repo.clone(work_dir) if !Dir.exist?(work_dir)
173
223
  Raykit::Git::Repository::work_pull(url)
174
224
  update_local_clone_directory
175
225
  end
176
226
 
177
227
  def work(command, force = false)
178
- pull if (!Dir.exist?(get_dev_dir("work")))
228
+ #pull if (!Dir.exist?(get_dev_dir("work")))
179
229
  fcommand = Raykit::FileSystem::replace_invalid_chars(command)
180
230
  filename = "#{Raykit::Environment::log_dir}/work_#{fcommand}_#{relative_path.gsub("/", "-")}.json"
181
231
  if (Raykit::Git::Directory.new(get_dev_dir("work")).outstanding_commit? || force)
@@ -189,11 +239,20 @@ module Raykit
189
239
  else
190
240
  work_cmd = Raykit::Git::Repository::work_url(url, command)
191
241
  work_cmd.save_as(filename)
242
+ update
192
243
  end
193
244
  #
194
245
  end
195
246
  end
196
247
 
248
+ def get_make_command(commit_id, command)
249
+ make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
250
+ fcommand = Raykit::FileSystem::replace_invalid_chars(command)
251
+ filename = "#{Raykit::Environment::log_dir}/#{make_id}_#{fcommand}.json"
252
+ return Raykit::Command::parse(IO.read(filename)) if (File.exist?(filename))
253
+ nil
254
+ end
255
+
197
256
  def make(command, force = false)
198
257
  commit_id = "#{latest_commit(default_branch)}"
199
258
  make_id = "make_#{relative_path.gsub("/", "-")}_#{commit_id}"
@@ -204,6 +263,7 @@ module Raykit
204
263
  else
205
264
  make_cmd = Raykit::Git::Repository::make_url(url, commit_id, "rake default")
206
265
  make_cmd.save_as(filename)
266
+ update
207
267
  return make_cmd
208
268
  end
209
269
  end
@@ -271,7 +331,21 @@ module Raykit
271
331
  end # def self.backup
272
332
 
273
333
  def to_s
274
- "Name: #{short_name}\nUrl: #{@url}\nRelative Path: #{relative_path}"
334
+ #short_name
335
+ latest_commit_id = @latest_commit_id.nil? ? "" : @latest_commit_id # latest_commit(default_branch)
336
+ latest_commit_exit_status = @latest_commit_exit_status.nil? ? nil : @latest_commit_exit_status # latest_commit(default_branch)
337
+ symbol = Raykit::Symbols::warning
338
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status == 0)
339
+ symbol = Raykit::Symbols::success if (!latest_commit_exit_status.nil? && latest_commit_exit_status != 0)
340
+ #latest_make_cmd = get_make_command(latest_commit_id, "rake default")
341
+ #commit = Rainbow(latest_commit(default_branch)[0..8]).cyan
342
+ #if (latest_make_cmd.nil?)
343
+ # symbol = Raykit::Symbols::warning
344
+ #else
345
+ # symbol = latest_make_cmd.exitstatus == 0 ? Raykit::Symbols::success : Raykit::Symbols::error
346
+ #end
347
+ commit = latest_commit_id[0..8]
348
+ "#{symbol} #{commit} #{short_name}"
275
349
  end # def to_s
276
350
 
277
351
  def to_table
@@ -282,11 +356,18 @@ module Raykit
282
356
  table = header
283
357
  table += "\n" + to_table_row("Name", short_name)
284
358
  table += "\n" + to_table_row("Url", @url)
359
+ table += "\n" + to_table_row("Default Branch", default_branch)
360
+ table += "\n" + to_table_row("Latest Commit", latest_commit(default_branch))
361
+ table += "\n" + to_table_row("Latest Commit Date", latest_commit_date(default_branch))
362
+ table += "\n" + to_table_row("Latest Commit Make", make("rake default").summary(false))
363
+ table += "\n" + to_table_row("Clone Directory", local_clone_directory)
364
+ table += "\n" + to_table_row("Work Directory", get_dev_dir("work"))
365
+ table += "\n" + to_table_row("Latest Tag", latest_tag(default_branch))
285
366
  table
286
367
  end # def to_table
287
368
 
288
369
  def to_table_row(name, value)
289
- max_name_width = 10
370
+ max_name_width = 20
290
371
  max_value_width = 30
291
372
  Rainbow(name.rjust(max_name_width, " ")).cyan + " | " + Rainbow(value).white.bold
292
373
  end
@@ -27,7 +27,9 @@ module Raykit
27
27
  end
28
28
 
29
29
  def update
30
- work = self["remote"].work_dir
30
+ repo = Raykit::Git::Repository.new(remote)
31
+ work = repo.get_dev_dir("work")
32
+ #work = self["remote"].work_dir
31
33
  work_parent = File.dirname(work)
32
34
  FileUtils.mkdir_p(work_parent) unless Dir.exist?(work_parent)
33
35
  if Dir.exist?(work)
@@ -0,0 +1,16 @@
1
+ module Raykit
2
+ class Symbols
3
+ def self.checkmark
4
+ Rainbow("\u2713").green
5
+ end
6
+ def self.success
7
+ Rainbow("\u2713").green
8
+ end
9
+ def self.error
10
+ Rainbow("\u0058").red
11
+ end
12
+ def self.warning
13
+ Rainbow("\u26A0").yellow
14
+ end
15
+ end # class Symbols
16
+ end # module Raykit
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.500
4
+ version: 0.0.501
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lou Parslow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - lib/raykit/sourceImport.rb
123
123
  - lib/raykit/sourceImports.rb
124
124
  - lib/raykit/string.rb
125
+ - lib/raykit/symbols.rb
125
126
  - lib/raykit/tasks.rb
126
127
  - lib/raykit/text.rb
127
128
  - lib/raykit/timer.rb