raykit 0.0.501 → 0.0.503

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +25 -20
  4. data/bin/raykit +6 -6
  5. data/lib/raykit/auto_setup.rb +69 -69
  6. data/lib/raykit/command.rb +373 -373
  7. data/lib/raykit/conan/buildinfo.rb +69 -69
  8. data/lib/raykit/conanpackage.rb +49 -49
  9. data/lib/raykit/configuration.rb +53 -50
  10. data/lib/raykit/console.rb +314 -308
  11. data/lib/raykit/default_content.rb +227 -227
  12. data/lib/raykit/dir.rb +49 -49
  13. data/lib/raykit/dotnet.rb +174 -174
  14. data/lib/raykit/environment.rb +114 -114
  15. data/lib/raykit/filesystem.rb +34 -34
  16. data/lib/raykit/git/commit.rb +16 -16
  17. data/lib/raykit/git/directory.rb +216 -216
  18. data/lib/raykit/git/files.rb +46 -46
  19. data/lib/raykit/git/repositories.rb +89 -89
  20. data/lib/raykit/git/repository.rb +376 -376
  21. data/lib/raykit/installer.rb +17 -17
  22. data/lib/raykit/log.rb +80 -80
  23. data/lib/raykit/logevent.rb +49 -49
  24. data/lib/raykit/logging.rb +57 -57
  25. data/lib/raykit/markdown.rb +21 -21
  26. data/lib/raykit/msbuild.rb +54 -54
  27. data/lib/raykit/nugetpackage.rb +54 -54
  28. data/lib/raykit/nunit.rb +13 -13
  29. data/lib/raykit/project.rb +343 -343
  30. data/lib/raykit/rake.rb +39 -39
  31. data/lib/raykit/runner.rb +42 -42
  32. data/lib/raykit/secrets.rb +38 -38
  33. data/lib/raykit/sourceImport.rb +76 -76
  34. data/lib/raykit/sourceImports.rb +43 -43
  35. data/lib/raykit/string.rb +18 -18
  36. data/lib/raykit/symbols.rb +16 -16
  37. data/lib/raykit/tasks.rb +99 -99
  38. data/lib/raykit/text.rb +32 -32
  39. data/lib/raykit/timer.rb +31 -31
  40. data/lib/raykit/version.rb +103 -103
  41. data/lib/raykit/vstest.rb +24 -24
  42. data/lib/raykit/wt.rb +28 -28
  43. data/lib/raykit/zip.rb +73 -73
  44. data/lib/raykit.rb +125 -125
  45. metadata +1 -1
@@ -1,308 +1,314 @@
1
- # frozen_string_literal: true
2
-
3
- require "optparse"
4
- require "slop"
5
- require_relative("./logging")
6
-
7
- module Raykit
8
- # The implementation for the raykit console application
9
- class Console
10
- attr_accessor :opts
11
-
12
- def self.get_opts
13
- Slop.parse do |o|
14
- o.string "-t", "--task", "rake task", default: "default"
15
- o.bool "-v", "--verbose", "print detailed output", default: false
16
- o.bool "-q", "--quiet", "minimal output", default: false
17
- o.bool "-s", "--stop", "stop on error", default: true
18
- end
19
- end # def self.get_opts
20
-
21
- def initialize(opts = nil)
22
- if opts.nil?
23
- @opts = Console.get_opts
24
- else
25
- @opts = opts
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
38
- end
39
-
40
- def run
41
- verb = "usage"
42
- verb = @opts.arguments[0] if @opts.arguments.length.positive?
43
- case verb
44
- when "usage"
45
- usage
46
- when "add"
47
- add
48
- when "remove"
49
- remove
50
- when "list"
51
- list
52
- when "show"
53
- show
54
- when "work"
55
- work
56
- when "import"
57
- import
58
- when "clean"
59
- clean
60
- when "sync_version"
61
- sync_version
62
- when "copy"
63
- copy
64
- when "pull"
65
- pull
66
- else
67
- puts "unrecognized command #{verb}"
68
- 1
69
- end
70
- end
71
-
72
- def verb_descriptions
73
- { "add" => "add a git url",
74
- "remove" => "remove one or more git urls",
75
- "list" => "list summaries of repositories",
76
- "show" => "show git urls matching a specific pattern",
77
- "work" => "clone and rake a git repository",
78
- "import" => "import git urls matching a specific pattern",
79
- "clean" => "clean one or more working directories",
80
- "pull" => "preform git pull on one or more working directories",
81
- "sync_version" => "synchronize the version number between two files",
82
- "copy" => "copy a file" }
83
- end
84
-
85
- def verb_usage
86
- { "add" => "add GIT_URL",
87
- "remove" => "remove URL_PATTERN",
88
- "show" => "show URL_PATTERN",
89
- "work" => "work URL_PATTERN [--task RAKE_TASK]",
90
- "import" => "import URL_PATTERN",
91
- "clean" => "clean URL_PATTERN",
92
- "pull" => "pull URL_PATTERN",
93
- "sync_version" => "sync_version SOURCE_FILENAME DESTINATION_FILENAME",
94
- "copy" => "copy SOURCE DESTINATION" }
95
- end
96
-
97
- def usage
98
- puts "Usage: raykit VERB [GIT_URL|PATTERN] [OPTIONS]"
99
- verb_descriptions.each do |k, v|
100
- puts "#{k.ljust(15, " ")} - #{v}"
101
- end
102
- # puts @opts
103
- # puts "verbs: " + verbs.to_s
104
- 0
105
- end
106
-
107
- def add
108
- if @opts.arguments.length < 2
109
- puts "add requires a url"
110
- return 1
111
- end
112
- url = @opts.arguments[1]
113
- if REPOSITORIES.include?(url)
114
- puts "url #{url} already exists."
115
- else
116
- REPOSITORIES << url
117
- REPOSITORIES.save(REPOSITORIES.filename)
118
- puts "url #{url} added."
119
- end
120
- end
121
-
122
- def remove
123
- if @opts.arguments.length < 2
124
- puts "remove requires a url or pattern"
125
- return 1
126
- end
127
- pattern = ""
128
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
129
- remove_urls = REPOSITORIES.matches(pattern)
130
- if remove_urls.length.zero?
131
- puts "no matching urls found."
132
- else
133
- remove_urls.each do |url|
134
- REPOSITORIES.delete(url)
135
- puts "url #{url} removed."
136
- end
137
- REPOSITORIES.save(REPOSITORIES.filename)
138
- end
139
- end
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
-
151
- def show
152
- pattern = ""
153
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
154
- REPOSITORIES.matches(pattern).each do |url|
155
- puts url
156
- end
157
- end
158
-
159
- def work
160
- pattern = ""
161
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
162
-
163
- work_repositories = REPOSITORIES.matches(pattern)
164
- errors = []
165
- puts "work: found #{work_repositories.length} matching urls"
166
- work_repositories.each do |url|
167
- default_command = "rake default"
168
- puts "work: #{url} #{default_command}"
169
- repo = Raykit::Git::Repository.new(url)
170
- cmd = repo.work default_command
171
- puts cmd.to_s
172
- #exitstatus = work_url(url)
173
- #puts " " if @opts.verbose?
174
- #return exitstatus if @opts[:stop] && exitstatus != 0
175
- end
176
- 0
177
- end
178
-
179
- #puts "\nwork \"rake default\""
180
- #cmd = repo.work "rake default"
181
- #puts cmd.to_s
182
-
183
- def work_url(url)
184
- return 0 if url == "https://gitlab.com/gems-rb/raykit.git"
185
-
186
- puts Rainbow(url).yellow.bright if @opts.verbose?
187
- repo = Raykit::Git::Repository.new(url)
188
- work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
189
- unless Dir.exist?(work.directory)
190
- clone = Command.new("git clone #{url} #{work.directory} --recursive")
191
- puts clone.summary unless @opts.quiet?
192
- if clone.exitstatus != 0
193
- clone.details
194
- return clone.exitstatus
195
- end
196
- end
197
- if Dir.exist?(work.directory)
198
- Dir.chdir(work.directory) do
199
- if File.exist?("rakefile.rb")
200
- rake = Raykit::Command.new("rake #{@opts[:task]}")
201
- rake.summary(true) if !@opts.quiet? || rake.exitstatus != 0
202
- if rake.exitstatus != 0
203
- rake.details
204
- rake.summary true
205
- return rake.exitstatus
206
- end
207
- else
208
- puts("rakefile.rb not found in #{work.directory}") if @opts.verbose?
209
- return 0
210
- end
211
- end
212
- end
213
- 0
214
- end
215
-
216
- def pull
217
- pattern = ""
218
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
219
- REPOSITORIES.matches(pattern).each do |url|
220
- repo = Raykit::Git::Repository.new(url)
221
- work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
222
- if Dir.exist?(work.directory) && !work.directory == ".git"
223
- Dir.chdir(work.directory) do
224
- diff = `git diff`.strip
225
- status = `git status`.strip
226
- if diff.length.zero? && status.include?("nothing to commit")
227
- cmd = Command.new("git pull")
228
- cmd.summary if @opts.verbose?
229
-
230
- if cmd.exitstatus != 0
231
- cmd.details
232
- abort Rainbow(cmd.summary).blue.bright if @opts.quit?
233
- end
234
- end
235
- end
236
- end
237
- rescue StandardError => e
238
- issue = "error occurred for pull of #{url} #{e}"
239
- if @opts.quit?
240
- abort Rainbow(issue).blue.bright
241
- else
242
- puts Rainbow(issue).blue.bright
243
- end
244
- end
245
- end
246
-
247
- def import
248
- pattern = ""
249
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
250
- puts "scanning..."
251
- count = REPOSITORIES.length
252
- REPOSITORIES.import(pattern)
253
- new_count = REPOSITORIES.length - count
254
- puts "imported #{new_count} git repositories"
255
- end
256
-
257
- def clean
258
- pattern = ""
259
- pattern = @opts.arguments[1] if @opts.arguments.length > 1
260
- REPOSITORIES.matches(pattern).each do |url|
261
- repo = Raykit::Git::Repository.new(url)
262
- work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
263
- next unless Dir.exist?(work.directory)
264
-
265
- puts "removing #{work.directory}"
266
- begin
267
- FileUtils.rm_rf(work.directory, secure: true)
268
- rescue StandardError
269
- puts "error removing #{work.directory}"
270
- end
271
- end
272
- end
273
-
274
- def copy
275
- if @opts.arguments.length < 3
276
- puts "source and destination arguments are required for copy"
277
- return 1
278
- end
279
- source = @opts.arguments[1]
280
- dest = @opts.arguments[2]
281
- FileUtils.cp(source, dest)
282
- puts "copied #{source} to #{dest}"
283
- end
284
-
285
- def rake(hash)
286
- REPOSITORIES.each do |remote|
287
- next unless remote.include?(hash[:pattern])
288
-
289
- begin
290
- puts "remote: #{remote}"
291
- cmd = Raykit::Rake.run(remote, "master")
292
- elapsed_str = Timer.get_elapsed_str(cmd.elapsed)
293
- if cmd.exitstatus.zero?
294
- puts "#{elapsed_str} #{Rainbow(SECRETS.hide(cmd.command)).yellow.bright} (#{cmd.directory})"
295
- else
296
- puts "\r\n#{cmd.command}\r\n"
297
- puts "\r\n#{cmd.output}\r\n"
298
- puts "\r\n#{cmd.error}\r\n"
299
- puts ""
300
- puts "#{Rainbow(elapsed_str).red.bright} #{Rainbow(cmd.command).white}"
301
- end
302
- rescue StandardError
303
- puts "rescued..."
304
- end
305
- end
306
- end
307
- end
308
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "slop"
5
+ require_relative("./logging")
6
+
7
+ module Raykit
8
+ # The implementation for the raykit console application
9
+ class Console
10
+ attr_accessor :opts
11
+
12
+ def self.get_opts
13
+ Slop.parse do |o|
14
+ o.string "-t", "--task", "rake task", default: "default"
15
+ o.bool "-v", "--verbose", "print detailed output", default: false
16
+ o.bool "-q", "--quiet", "minimal output", default: false
17
+ o.bool "-s", "--stop", "stop on error", default: true
18
+ end
19
+ end # def self.get_opts
20
+
21
+ def initialize(opts = nil)
22
+ if opts.nil?
23
+ @opts = Console.get_opts
24
+ else
25
+ @opts = opts
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
38
+ end
39
+
40
+ def run
41
+ verb = "usage"
42
+ verb = @opts.arguments[0] if @opts.arguments.length.positive?
43
+ case verb
44
+ when "usage"
45
+ usage
46
+ when "add"
47
+ add
48
+ when "remove"
49
+ remove
50
+ when "list"
51
+ list
52
+ when "show"
53
+ show
54
+ when "work"
55
+ work
56
+ when "import"
57
+ import
58
+ when "clean"
59
+ clean
60
+ when "sync_version"
61
+ sync_version
62
+ when "copy"
63
+ copy
64
+ when "pull"
65
+ pull
66
+ else
67
+ puts "unrecognized command #{verb}"
68
+ 1
69
+ end
70
+ end
71
+
72
+ def verb_descriptions
73
+ { "add" => "add a git url",
74
+ "remove" => "remove one or more git urls",
75
+ "list" => "list summaries of repositories",
76
+ "show" => "show git urls matching a specific pattern",
77
+ "work" => "clone and rake a git repository",
78
+ "import" => "import git urls matching a specific pattern",
79
+ "clean" => "clean one or more working directories",
80
+ "pull" => "preform git pull on one or more working directories",
81
+ "sync_version" => "synchronize the version number between two files",
82
+ "copy" => "copy a file" }
83
+ end
84
+
85
+ def verb_usage
86
+ { "add" => "add GIT_URL",
87
+ "remove" => "remove URL_PATTERN",
88
+ "show" => "show URL_PATTERN",
89
+ "work" => "work URL_PATTERN [--task RAKE_TASK]",
90
+ "import" => "import URL_PATTERN",
91
+ "clean" => "clean URL_PATTERN",
92
+ "pull" => "pull URL_PATTERN",
93
+ "sync_version" => "sync_version SOURCE_FILENAME DESTINATION_FILENAME",
94
+ "copy" => "copy SOURCE DESTINATION" }
95
+ end
96
+
97
+ def usage
98
+ puts "Usage: raykit VERB [GIT_URL|PATTERN] [OPTIONS]"
99
+ verb_descriptions.each do |k, v|
100
+ puts "#{k.ljust(15, " ")} - #{v}"
101
+ end
102
+ # puts @opts
103
+ # puts "verbs: " + verbs.to_s
104
+ 0
105
+ end
106
+
107
+ def add
108
+ if @opts.arguments.length < 2
109
+ puts "add requires a url"
110
+ return 1
111
+ end
112
+ url = @opts.arguments[1]
113
+ if REPOSITORIES.include?(url)
114
+ puts "url #{url} already exists."
115
+ else
116
+ REPOSITORIES << url
117
+ REPOSITORIES.save(REPOSITORIES.filename)
118
+ puts "url #{url} added."
119
+ end
120
+ end
121
+
122
+ def remove
123
+ if @opts.arguments.length < 2
124
+ puts "remove requires a url or pattern"
125
+ return 1
126
+ end
127
+ pattern = ""
128
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
129
+ remove_urls = REPOSITORIES.matches(pattern)
130
+ if remove_urls.length.zero?
131
+ puts "no matching urls found."
132
+ else
133
+ remove_urls.each do |url|
134
+ REPOSITORIES.delete(url)
135
+ puts "url #{url} removed."
136
+ end
137
+ REPOSITORIES.save(REPOSITORIES.filename)
138
+ end
139
+ end
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
+
151
+ def show
152
+ pattern = ""
153
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
154
+ REPOSITORIES.matches(pattern).each do |url|
155
+ puts url
156
+ end
157
+ end
158
+
159
+ def work
160
+ pattern = ""
161
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
162
+ logger = Logger.new(STDOUT)
163
+ logger.level = Configuration.new().log_level
164
+ logger.debug("work: pattern: #{pattern}")
165
+
166
+ work_repositories = REPOSITORIES.matches(pattern)
167
+ errors = []
168
+ logger.info("work: found #{work_repositories.length} matching urls")
169
+ #puts "work: found #{work_repositories.length} matching urls"
170
+ work_repositories.each do |url|
171
+ default_command = "rake default"
172
+ logger.info("work: #{url} #{default_command}")
173
+ #puts "work: #{url} #{default_command}"
174
+ repo = Raykit::Git::Repository.new(url)
175
+ cmd = repo.work default_command
176
+ logger.info(cmd.to_s)
177
+ #puts cmd.to_s
178
+ #exitstatus = work_url(url)
179
+ #puts " " if @opts.verbose?
180
+ #return exitstatus if @opts[:stop] && exitstatus != 0
181
+ end
182
+ 0
183
+ end
184
+
185
+ #puts "\nwork \"rake default\""
186
+ #cmd = repo.work "rake default"
187
+ #puts cmd.to_s
188
+
189
+ def work_url(url)
190
+ return 0 if url == "https://gitlab.com/gems-rb/raykit.git"
191
+
192
+ puts Rainbow(url).yellow.bright if @opts.verbose?
193
+ repo = Raykit::Git::Repository.new(url)
194
+ work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
195
+ unless Dir.exist?(work.directory)
196
+ clone = Command.new("git clone #{url} #{work.directory} --recursive")
197
+ puts clone.summary unless @opts.quiet?
198
+ if clone.exitstatus != 0
199
+ clone.details
200
+ return clone.exitstatus
201
+ end
202
+ end
203
+ if Dir.exist?(work.directory)
204
+ Dir.chdir(work.directory) do
205
+ if File.exist?("rakefile.rb")
206
+ rake = Raykit::Command.new("rake #{@opts[:task]}")
207
+ rake.summary(true) if !@opts.quiet? || rake.exitstatus != 0
208
+ if rake.exitstatus != 0
209
+ rake.details
210
+ rake.summary true
211
+ return rake.exitstatus
212
+ end
213
+ else
214
+ puts("rakefile.rb not found in #{work.directory}") if @opts.verbose?
215
+ return 0
216
+ end
217
+ end
218
+ end
219
+ 0
220
+ end
221
+
222
+ def pull
223
+ pattern = ""
224
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
225
+ REPOSITORIES.matches(pattern).each do |url|
226
+ repo = Raykit::Git::Repository.new(url)
227
+ work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
228
+ if Dir.exist?(work.directory) && !work.directory == ".git"
229
+ Dir.chdir(work.directory) do
230
+ diff = `git diff`.strip
231
+ status = `git status`.strip
232
+ if diff.length.zero? && status.include?("nothing to commit")
233
+ cmd = Command.new("git pull")
234
+ cmd.summary if @opts.verbose?
235
+
236
+ if cmd.exitstatus != 0
237
+ cmd.details
238
+ abort Rainbow(cmd.summary).blue.bright if @opts.quit?
239
+ end
240
+ end
241
+ end
242
+ end
243
+ rescue StandardError => e
244
+ issue = "error occurred for pull of #{url} #{e}"
245
+ if @opts.quit?
246
+ abort Rainbow(issue).blue.bright
247
+ else
248
+ puts Rainbow(issue).blue.bright
249
+ end
250
+ end
251
+ end
252
+
253
+ def import
254
+ pattern = ""
255
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
256
+ puts "scanning..."
257
+ count = REPOSITORIES.length
258
+ REPOSITORIES.import(pattern)
259
+ new_count = REPOSITORIES.length - count
260
+ puts "imported #{new_count} git repositories"
261
+ end
262
+
263
+ def clean
264
+ pattern = ""
265
+ pattern = @opts.arguments[1] if @opts.arguments.length > 1
266
+ REPOSITORIES.matches(pattern).each do |url|
267
+ repo = Raykit::Git::Repository.new(url)
268
+ work = Raykit::Git::Directory.new(repo.get_dev_dir("work"))
269
+ next unless Dir.exist?(work.directory)
270
+
271
+ puts "removing #{work.directory}"
272
+ begin
273
+ FileUtils.rm_rf(work.directory, secure: true)
274
+ rescue StandardError
275
+ puts "error removing #{work.directory}"
276
+ end
277
+ end
278
+ end
279
+
280
+ def copy
281
+ if @opts.arguments.length < 3
282
+ puts "source and destination arguments are required for copy"
283
+ return 1
284
+ end
285
+ source = @opts.arguments[1]
286
+ dest = @opts.arguments[2]
287
+ FileUtils.cp(source, dest)
288
+ puts "copied #{source} to #{dest}"
289
+ end
290
+
291
+ def rake(hash)
292
+ REPOSITORIES.each do |remote|
293
+ next unless remote.include?(hash[:pattern])
294
+
295
+ begin
296
+ puts "remote: #{remote}"
297
+ cmd = Raykit::Rake.run(remote, "master")
298
+ elapsed_str = Timer.get_elapsed_str(cmd.elapsed)
299
+ if cmd.exitstatus.zero?
300
+ puts "#{elapsed_str} #{Rainbow(SECRETS.hide(cmd.command)).yellow.bright} (#{cmd.directory})"
301
+ else
302
+ puts "\r\n#{cmd.command}\r\n"
303
+ puts "\r\n#{cmd.output}\r\n"
304
+ puts "\r\n#{cmd.error}\r\n"
305
+ puts ""
306
+ puts "#{Rainbow(elapsed_str).red.bright} #{Rainbow(cmd.command).white}"
307
+ end
308
+ rescue StandardError
309
+ puts "rescued..."
310
+ end
311
+ end
312
+ end
313
+ end
314
+ end