version_boss 0.1.0

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.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module VersionBoss
6
+ module Gem
7
+ module VersionFileSources
8
+ # Checks for the gem's version in a file named VERSION
9
+ #
10
+ # @api public
11
+ #
12
+ class Version < Base
13
+ # The regexp to find the version and surrounding content within the version file
14
+ VERSION_REGEXP = /
15
+ \A
16
+ (?<content_before>\s*)
17
+ (?<version>#{REGEXP.source})
18
+ (?<content_after>\s*)
19
+ \z
20
+ /x
21
+
22
+ private
23
+
24
+ # The version file regexp
25
+ # @return [Regexp]
26
+ # @api private
27
+ private_class_method def self.content_regexp = VERSION_REGEXP
28
+
29
+ # A glob that matches potential version files
30
+ # @return [String]
31
+ # @api private
32
+ private_class_method def self.glob = 'VERSION'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module VersionBoss
6
+ module Gem
7
+ module VersionFileSources
8
+ # Checks for the gem's version in a file named lib/**/version.rb
9
+ #
10
+ # @api public
11
+ #
12
+ class VersionRb < Base
13
+ # The regexp to find the version and surrounding content within the version.rb file
14
+ VERSION_REGEXP = /
15
+ \A
16
+ (?<content_before>
17
+ .*
18
+ VERSION\s*=\s*(?<quote>['"])
19
+ )
20
+ (?<version>#{REGEXP.source})
21
+ (?<content_after>\k<quote>.*)
22
+ \z
23
+ /xm
24
+
25
+ private
26
+
27
+ # The version file regexp
28
+ # @return [Regexp]
29
+ # @api private
30
+ private_class_method def self.content_regexp = VERSION_REGEXP
31
+
32
+ # A glob that matches potential version files
33
+ # @return [String]
34
+ # @api private
35
+ private_class_method def self.glob = 'lib/**/version.rb'
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version_file_sources/base'
4
+ require_relative 'version_file_sources/gemspec'
5
+ require_relative 'version_file_sources/version'
6
+ require_relative 'version_file_sources/version_rb'
7
+
8
+ module VersionBoss
9
+ module Gem
10
+ # Module containing version file sources used by VersionBoss::Gem::VersionFileFactory
11
+ module VersionFileSources
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VersionBoss
4
+ # Classes for working with Gem versions
5
+ module Gem; end
6
+ end
7
+
8
+ require_relative 'gem/command_line'
9
+ require_relative 'gem/incrementable_version'
10
+ require_relative 'gem/regexp'
11
+ require_relative 'gem/version_file_factory'
12
+ require_relative 'gem/version_file_sources'
13
+ require_relative 'gem/version_file'
14
+ require_relative 'gem/version'
@@ -0,0 +1,474 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require 'thor'
4
+
5
+ # module VersionBoss
6
+ # module Semver
7
+ # # The version_boss cli
8
+ # #
9
+ # # @example
10
+ # # require 'version_boss'
11
+ # #
12
+ # # VersionBoss::CommandLine.start(ARGV)
13
+ # #
14
+ # # @api private
15
+ # #
16
+ # class CommandLine < Thor
17
+ # # Tell Thor to exit with a non-zero status code if a command fails
18
+ # def self.exit_on_failure? = true
19
+
20
+ # desc 'current [-q]', 'Show the current gem version'
21
+
22
+ # long_desc <<-LONG_DESC
23
+ # Output the current gem version from the file that stores the gem version.
24
+
25
+ # The command fails if the gem version could not be found or is invalid.
26
+
27
+ # Use `--quiet` to ensure that a gem version could be found and is valid without producing any output.
28
+ # LONG_DESC
29
+
30
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the current version to stdout'
31
+
32
+ # # Show the current gem version
33
+ # # @return [void]
34
+ # def current
35
+ # version_file = VersionBoss::Gem::VersionFileFactory.find
36
+
37
+ # if version_file.nil?
38
+ # warn 'version file not found or is not valid' unless options[:quiet]
39
+ # exit 1
40
+ # end
41
+
42
+ # puts version_file.version unless options[:quiet]
43
+ # end
44
+
45
+ # desc 'file [-q]', 'Show the path to the file containing the gem version'
46
+
47
+ # long_desc <<-LONG_DESC
48
+ # Output the relative path to the file that stores the gem version.
49
+
50
+ # The command fails if the gem version could not be found.
51
+
52
+ # Use `--quiet` to ensure that a gem version could be found without producing any output.
53
+ # LONG_DESC
54
+
55
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the version file path to stdout'
56
+
57
+ # # Show the gem's version file
58
+ # # @return [void]
59
+ # def file
60
+ # version_file = VersionBoss::Gem::VersionFileFactory.find
61
+
62
+ # if version_file.nil?
63
+ # warn 'version file not found or is not valid' unless options[:quiet]
64
+ # exit 1
65
+ # end
66
+
67
+ # puts version_file.path unless options[:quiet]
68
+ # end
69
+
70
+ # desc 'next-major [VERSION] [-p [-t TYPE]] [-b BUILD] [-n] [-q]', "Increment the version's major part"
71
+
72
+ # long_desc <<-LONG_DESC
73
+ # Increase the current gem version to the next major version, update the
74
+ # file that stores the version, and output the resulting version to stdout.
75
+
76
+ # Increments 1.x.y to 2.0.0.
77
+
78
+ # The command fails if the current gem version file could not be found or
79
+ # if the version is not valid.
80
+
81
+ # If VERSION is given, use that instead of the current gem version. Giving
82
+ # VERSION implies --dry-run. The command fails if VERSION is not valid.
83
+
84
+ # --pre can be used to specify that the version should be incremented AND
85
+ # given a pre-release part. For instance:
86
+
87
+ # $ version_boss next-major --pre
88
+
89
+ # increments '1.2.3' to '2.0.0.pre.1'.
90
+
91
+ # By default, the pre-release type is 'pre'. --pre-type=TYPE can be used with
92
+ # --pre to specify a different pre-release type such as alpha, beta, rc, etc.
93
+ # For instance:
94
+
95
+ # $ version_boss next-major --pre --pre-type=alpha
96
+
97
+ # increments '1.2.3' to '2.0.0-alpha.1'.
98
+
99
+ # The command fails if the existing pre-release type is not lexically less than or
100
+ # equal to TYPE. For example, it the current version is '1.2.3-beta.1' and TYPE
101
+ # is 'alpha', the the command will fail since the new version would sort before the
102
+ # existing version ('beta' is not less than or equal to 'alpha').
103
+
104
+ # Use --build=BUILD to set the build metadata for the new version (See
105
+ # [Build Metadata in the Semantic Versioning Specification](https://semver.org/spec/v2.0.0.html#spec-item-10)).
106
+ # If --build is not given, the incremented version retain the previous build
107
+ # metadata. Pass an empty string to remove the build metadata (--build="")
108
+
109
+ # Use --dry-run to run this command without updating the version file.
110
+
111
+ # Use --quiet to increment the version without producing any output.
112
+ # LONG_DESC
113
+
114
+ # option :pre, type: :boolean, aliases: '-p', desc: 'Create a pre-release version'
115
+ # option :'pre-type', type: :string, aliases: '-t', default: 'pre', banner: 'TYPE',
116
+ # desc: 'The type of pre-release version (alpha, beta, etc.)'
117
+ # option :build, type: :string, aliases: '-b', desc: 'The build metadata to add to the version'
118
+ # option :'dry-run', type: :boolean, aliases: '-n', desc: 'Do not write the new version to the version file'
119
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the new version to stdout'
120
+
121
+ # # Increment the gem version's major part
122
+ # # @param version [String, nil] The version to increment or nil to use the version
123
+ # # from the gem's version file
124
+ # # @return [void]
125
+ # def next_major(version = nil)
126
+ # increment_core_version(:next_major, version)
127
+ # end
128
+
129
+ # desc 'next-minor [VERSION] [-p [-t TYPE]] [-b BUILD] [-n] [-q]', "Increment the version's minor part"
130
+
131
+ # long_desc <<-LONG_DESC
132
+ # Increase the current gem version to the next minor version, update the
133
+ # file that stores the version, and output the resulting version to stdout.
134
+
135
+ # Increments 1.2.y to 1.3.0.
136
+
137
+ # The command fails if the current gem version file could not be found or
138
+ # if the version is not valid.
139
+
140
+ # If VERSION is given, use that instead of the current gem version. Giving
141
+ # VERSION implies --dry-run. The command fails if VERSION is not valid.
142
+
143
+ # --pre can be used to specify that the version should be incremented AND
144
+ # given a pre-release part. For instance:
145
+
146
+ # $ version_boss next-minor --pre
147
+
148
+ # increments '1.2.3' to '2.0.0.pre.1'.
149
+
150
+ # By default, the pre-release type is 'pre'. --pre-type=TYPE can be used with
151
+ # --pre to specify a different pre-release type such as alpha, beta, rc, etc.
152
+ # For instance:
153
+
154
+ # $ version_boss next-patch --pre --pre-type=alpha
155
+
156
+ # increments '1.2.3' to '1.2.4-alpha.1'.
157
+
158
+ # The command fails if the existing pre-release type is not lexically less than or
159
+ # equal to TYPE. For example, it the current version is '1.2.3-beta.1' and TYPE
160
+ # is 'alpha', the the command will fail since the new version would sort before the
161
+ # existing version ('beta' is not less than or equal to 'alpha').
162
+
163
+ # Use --build=BUILD to set the build metadata for the new version (See
164
+ # [Build Metadata in the Semantic Versioning Specification](https://semver.org/spec/v2.0.0.html#spec-item-10)).
165
+ # If --build is not given, the incremented version retain the previous build
166
+ # metadata. Pass an empty string to remove the build metadata (--build="")
167
+
168
+ # Use --dry-run to run this command without updating the version file.
169
+
170
+ # Use --quiet to increment the version without producing any output.
171
+ # LONG_DESC
172
+
173
+ # option :pre, type: :boolean, aliases: '-p', desc: 'Create a pre-release version'
174
+ # option :'pre-type', type: :string, aliases: '-t', default: 'pre', banner: 'TYPE',
175
+ # desc: 'The type of pre-release version (alpha, beta, etc.)'
176
+ # option :build, type: :string, aliases: '-b', desc: 'The build metadata to add to the version'
177
+ # option :'dry-run', type: :boolean, aliases: '-n', desc: 'Do not write the new version to the version file'
178
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the new version to stdout'
179
+
180
+ # # Increment the gem version's minor part
181
+ # # @param version [String, nil] The version to increment or nil to use the version
182
+ # # from the gem's version file
183
+ # # @return [void]
184
+ # def next_minor(version = nil)
185
+ # increment_core_version(:next_minor, version)
186
+ # end
187
+
188
+ # desc 'next-patch [VERSION] [-p [-t TYPE]] [-b BUILD] [-n] [-q]', "Increment the version's patch part"
189
+
190
+ # long_desc <<-LONG_DESC
191
+ # Increase the current gem version to the next patch version, update the
192
+ # file that stores the version, and output the resulting version to stdout.
193
+
194
+ # Increments 1.2.3 to 1.2.4.
195
+
196
+ # The command fails if the current gem version file could not be found or
197
+ # if the version is not valid.
198
+
199
+ # If VERSION is given, use that instead of the current gem version. Giving
200
+ # VERSION implies --dry-run. The command fails if VERSION is not valid.
201
+
202
+ # --pre can be used to specify that the version should be incremented AND
203
+ # given a pre-release part. For instance:
204
+
205
+ # $ version_boss next-patch --pre
206
+
207
+ # increments '1.2.3' to '1.2.4.pre.1'.
208
+
209
+ # By default, the pre-release type is 'pre'. --pre-type=TYPE can be used with
210
+ # --pre to specify a different pre-release type such as alpha, beta, rc, etc.
211
+ # For instance:
212
+
213
+ # $ version_boss next-patch --pre --pre-type=alpha
214
+
215
+ # increments '1.2.3' to '1.2.4-alpha.1'.
216
+
217
+ # The command fails if the existing pre-release type is not lexically less than or
218
+ # equal to TYPE. For example, it the current version is '1.2.3-beta.1' and TYPE
219
+ # is 'alpha', the the command will fail since the new version would sort before the
220
+ # existing version ('beta' is not less than or equal to 'alpha').
221
+
222
+ # Use --build=BUILD to set the build metadata for the new version (See
223
+ # [Build Metadata in the Semantic Versioning Specification](https://semver.org/spec/v2.0.0.html#spec-item-10)).
224
+ # If --build is not given, the incremented version retain the previous build
225
+ # metadata. Pass an empty string to remove the build metadata (--build="")
226
+
227
+ # Use --dry-run to run this command without updating the version file.
228
+
229
+ # Use --quiet to increment the version without producing any output.
230
+ # LONG_DESC
231
+
232
+ # option :pre, type: :boolean, aliases: '-p', desc: 'Create a pre-release version'
233
+ # option :'pre-type', type: :string, aliases: '-t', default: 'pre', banner: 'TYPE',
234
+ # desc: 'The type of pre-release version (alpha, beta, etc.)'
235
+ # option :build, type: :string, aliases: '-b', desc: 'The build metadata to add to the version'
236
+ # option :'dry-run', type: :boolean, aliases: '-n', desc: 'Do not write the new version to the version file'
237
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the new version to stdout'
238
+
239
+ # # Increment the gem version's patch part
240
+ # # @param version [String, nil] The version to increment or nil to use the version
241
+ # # from the gem's version file
242
+ # # @return [void]
243
+ # def next_patch(version = nil)
244
+ # increment_core_version(:next_patch, version)
245
+ # end
246
+
247
+ # desc 'next-pre [VERSION] [-t TYPE] [-b BUILD] [-n] [-q]', "Increment the version's pre-release part"
248
+
249
+ # long_desc <<-LONG_DESC
250
+ # Increase the current gem version to the next pre-release version, update the
251
+ # file that stores the version, and output the resulting version to stdout.
252
+
253
+ # The command fails if the current gem version file could not be found or
254
+ # the version is not a valid pre-release version.
255
+
256
+ # If VERSION is given, use that instead of the current gem version. Giving
257
+ # VERSION implies --dry-run. The command fails if VERSION is not a valid
258
+ # pre-release version.
259
+
260
+ # By default, the existing pre-release type is preserved. For instance:
261
+
262
+ # $ version_boss next-pre
263
+
264
+ # Increments 1.2.3-alpha.1 to 1.2.3-alpha.2.
265
+
266
+ # --pre-type=TYPE can be used to change the pre-release type to TYPE (typical
267
+ # examples include alpha, beta, rc, etc.). If the pre-release type is changed,
268
+ # the pre-release number is reset to 1.
269
+
270
+ # For example, if the version starts as 1.2.3-alpha.4, then:
271
+
272
+ # $ version_boss current
273
+ # 1.2.3-alpha.4
274
+ # $ semver next-pre --pre-type=beta
275
+ # 1.2.3-beta.1
276
+ # $ semver next-pre --pre-type=beta
277
+ # 1.2.3-beta.2
278
+ # $ semver next-pre --pre-type=rc
279
+ # 1.2.3-rc.1
280
+ # $ version_boss next-release
281
+ # 1.2.3
282
+
283
+ # The command fails if the existing pre-release type is not lexically less than or
284
+ # equal to TYPE. For example, it the current version is '1.2.3-beta.1' and the TYPE
285
+ # given type is 'alpha', then the command will fail since the new version would sort
286
+ # before the existing version (since 'beta' is not <= 'alpha').
287
+
288
+ # Use --build=BUILD to set the build metadata for the new version (See
289
+ # [Build Metadata in the Semantic Versioning Specification](https://semver.org/spec/v2.0.0.html#spec-item-10)).
290
+ # If --build is not given, the incremented version retain the previous build
291
+ # metadata. Pass an empty string to remove the build metadata (--build="")
292
+
293
+ # Use --dry-run to run this command without updating the version file.
294
+
295
+ # Use --quiet to increment the version without producing any output.
296
+ # LONG_DESC
297
+
298
+ # option :'pre-type', type: :string, aliases: '-t', banner: 'TYPE',
299
+ # desc: 'The type of pre-release version (alpha, beta, etc.)'
300
+ # option :build, type: :string, aliases: '-b', desc: 'The build metadata to add to the version'
301
+ # option :'dry-run', type: :boolean, aliases: '-n', desc: 'Do not write the new version to the version file'
302
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the new version to stdout'
303
+
304
+ # # Increment the gem version's pre-release part
305
+ # # @param version [String, nil] The version to increment or nil to use the version
306
+ # # from the gem's version file
307
+ # # @return [void]
308
+ # def next_pre(version = nil)
309
+ # args = {}
310
+ # args[:pre_type] = options[:'pre-type'] if options[:'pre-type']
311
+ # args[:build_metadata] = options[:build] if options[:build]
312
+
313
+ # new_version = increment_version(:next_pre, args, version)
314
+
315
+ # puts new_version unless options[:quiet]
316
+ # end
317
+
318
+ # desc 'next-release [VERSION] [-b BUILD] [-n] [-q]', 'Increment a pre-release version to the release version'
319
+
320
+ # long_desc <<-LONG_DESC
321
+ # Increase the current gem version to the next release version, update the
322
+ # file that stores the version, and output the resulting version to stdout.
323
+
324
+ # Increments 1.2.3-rc.4 to 1.2.3.
325
+
326
+ # The command fails if the current gem version file could not be found or
327
+ # the version is not a valid pre-release version.
328
+
329
+ # If VERSION is given, use that instead of the current gem version. Giving
330
+ # VERSION implies --dry-run. The command fails if VERSION is not a valid
331
+ # pre-release version.
332
+
333
+ # Use --build=BUILD to set the build metadata for the new version (See
334
+ # [Build Metadata in the Semantic Versioning Specification](https://semver.org/spec/v2.0.0.html#spec-item-10)).
335
+ # If --build is not given, the incremented version retain the previous build
336
+ # metadata. Pass an empty string to remove the build metadata (--build="")
337
+
338
+ # Use --dry-run to run this command without updating the version file.
339
+
340
+ # Use --quiet to increment the version without producing any output.
341
+ # LONG_DESC
342
+
343
+ # option :build, type: :string, aliases: '-b', desc: 'The build metadata to add to the version'
344
+ # option :'dry-run', type: :boolean, aliases: '-n', desc: 'Do not write the new version to the version file'
345
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the new version to stdout'
346
+
347
+ # # Increment the gem's pre-release version to a release version
348
+ # # @param version [String, nil] The version to increment or nil to use the version
349
+ # # from the gem's version file
350
+ # # @return [void]
351
+ # def next_release(version = nil)
352
+ # args = {}
353
+ # args[:build_metadata] = options[:build] if options[:build]
354
+
355
+ # new_version = increment_version(:next_release, args, version)
356
+
357
+ # puts new_version unless options[:quiet]
358
+ # end
359
+
360
+ # desc 'validate VERSION [-q]', 'Validate the given version'
361
+
362
+ # long_desc <<-LONG_DESC
363
+ # Validate and output the given gem version.
364
+
365
+ # The command fails if the gem version is not valid.
366
+
367
+ # Use `--quiet` to validate the gem version without producing any output.
368
+ # LONG_DESC
369
+
370
+ # option :quiet, type: :boolean, aliases: '-q', desc: 'Do not print the given version to stdout'
371
+
372
+ # # Validate that the give version is a valid IncrementableSemver version
373
+ # # @param version [String] The version to validate
374
+ # # @return [void]
375
+ # #
376
+ # def validate(version)
377
+ # VersionBoss::Gem::IncrementableVersion.new(version)
378
+ # rescue VersionBoss::Error => e
379
+ # warn e.message unless options[:quiet]
380
+ # exit 1
381
+ # else
382
+ # puts version unless options[:quiet]
383
+ # end
384
+
385
+ # private
386
+
387
+ # # Build a hash of arguments to pass to the IncrementableSemver methods
388
+ # #
389
+ # # These arguments are specificly for the #next_major, #next_minor, and
390
+ # # #next_patch method.
391
+ # #
392
+ # # @return [Hash]
393
+ # #
394
+ # def core_args
395
+ # {}.tap do |args|
396
+ # args[:pre] = options[:pre] if options[:pre]
397
+ # args[:pre_type] = options[:'pre-type'] if options[:'pre-type']
398
+ # args[:build_metadata] = options[:build] if options[:build]
399
+ # end
400
+ # end
401
+
402
+ # # Increment the gem's major, minor, or patch version
403
+ # #
404
+ # # @param method [Symbol] The method to call on the IncrementableSemver object
405
+ # # @param version [String, nil] The version to increment or nil to use the version
406
+ # # from the gem's version file
407
+ # #
408
+ # # @return [Void]
409
+ # #
410
+ # def increment_core_version(method, version)
411
+ # new_version = increment_version(method, core_args, version)
412
+
413
+ # puts new_version unless options[:quiet]
414
+ # end
415
+
416
+ # # Increment the gem's version
417
+ # #
418
+ # # @param method [Symbol] The method to call on the IncrementableSemver object
419
+ # #
420
+ # # The method can bee one of: :next_major, :next_minor, :next_patch, :next_pre, :next_release
421
+ # #
422
+ # # @param args [Hash] The arguments to pass to the method
423
+ # #
424
+ # # @param version [String, nil] The version to increment or nil to use the version
425
+ # #
426
+ # # @return [Void]
427
+ # #
428
+ # def increment_version(method, args, version)
429
+ # if version
430
+ # increment_literal_version(method, args, version)
431
+ # else
432
+ # increment_gem_version(method, args)
433
+ # end
434
+ # rescue VersionBoss::Error => e
435
+ # warn e.message unless options[:quiet]
436
+ # exit 1
437
+ # end
438
+
439
+ # # Increment a literal version from a string
440
+ # #
441
+ # # @param method [Symbol] The method to call on the IncrementableSemver object
442
+ # # @param args [Hash] The arguments to pass to the method
443
+ # # @param version [String] The version to increment
444
+ # #
445
+ # # @return [VersionBoss::IncrementableRubyVersion] the incremented version
446
+ # # @raise [VersionBoss::Error] if the version is not a valid IncrementableSemver version
447
+ # #
448
+ # def increment_literal_version(method, args, version)
449
+ # VersionBoss::Gem::IncrementableVersion.new(version).send(method, **args)
450
+ # end
451
+
452
+ # # Increment the gem's version from the gem's version file
453
+ # #
454
+ # # @param method [Symbol] The method to call on the IncrementableSemver object
455
+ # # @param args [Hash] The arguments to pass to the method
456
+ # #
457
+ # # @return [VersionBoss::IncrementableRubyVersion] the incremented version
458
+ # # @raise [VersionBoss::Error] if the version is not a valid IncrementableSemver version
459
+ # #
460
+ # def increment_gem_version(method, args)
461
+ # version_file = VersionBoss::Gem::VersionFileFactory.find
462
+
463
+ # if version_file.nil?
464
+ # warn 'version file not found or is not valid' unless options[:quiet]
465
+ # exit 1
466
+ # end
467
+
468
+ # version_file&.version.send(method, **args).tap do |new_version|
469
+ # version_file.version = new_version unless options[:'dry-run']
470
+ # end
471
+ # end
472
+ # end
473
+ # end
474
+ # end