raykit 0.0.526 → 0.0.529

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