devex 0.3.8 → 0.3.9

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: 91dabc0fdfce840ecaa864cbc1399b52d8cfe9ff1dea3038a80ffa87a2c1da8a
4
- data.tar.gz: 9389c09c2dfc38eb852785b05e9672a36e055f22f35f0f1ee4050da95db27a27
3
+ metadata.gz: 63d30abae077b9da745cbee6677950dd8f762674f90c78ab42f10073191a10e2
4
+ data.tar.gz: 2d94983e5b70cb7872485be76a27b432d852e51a97b71a6dfcf7138065da099b
5
5
  SHA512:
6
- metadata.gz: f605ee08b0bc4a716699e55c1c92e8049ebfe17d7685657640b35d3ed1ccf85e56778de9aefdb35e164c9759b2d8896f367a6708e61bbfc10fa86bfa9984fbd1
7
- data.tar.gz: '0641979e5dac9019bf8ea4cca642732e78e5da1efcaf0c4db1479703f1909f586c511a6f2966894f3fbcf2a2dcefc418bcbd795547f4990a53e46e2b08eed952'
6
+ metadata.gz: bc57c8ee43f849232f4408022a8d7aba30f7bfe7ed576ce25234323752b275d954f383057555676c60acd2af8e698dfbc8f6d09ea629b78f0cc275e96b60dcf0
7
+ data.tar.gz: d51afcd36c281f9bffee5c2cf622a51bf68bf225bc147f77d3425044156b6d1c764fb784fab1213e7c6a08c582ef403cb7f04f73e443524e92f5cffb815463c0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  All notable changes to devex will be documented in this file.
4
4
 
5
+ ## [0.3.9] - 2026-11-20
6
+
7
+ ### Added
8
+ - **Named version files.** A project with more than one version (a
9
+ specification and its implementation, say) can name further version files
10
+ in its dx config (`.dx.yml` or `.dx/config.yml`):
11
+
12
+ ```yaml
13
+ versions:
14
+ spec: VERSION.SPEC
15
+ ```
16
+
17
+ and address one by putting the name first: `dx version spec`,
18
+ `dx version spec bump pre`, `dx version spec set 2.0.0-beta.0`. Paths are
19
+ relative to the project root; a named file may be a bare version file or
20
+ Ruby source with a `VERSION = "…"` constant. `bump`, `set` and `help`
21
+ cannot be used as names.
22
+ - The unnamed commands are unchanged and keep finding the default version
23
+ file by convention. One addition: `dx version` in a project that has named
24
+ versions but no default file lists the named versions, where it used to
25
+ fall through to printing devex's own version.
26
+
27
+ ### Fixed
28
+ - `dx version <unknown word>` is now an error (exit 1). It used to ignore
29
+ the extra arguments and show the version, so a typo like
30
+ `dx version bmup patch` looked like success.
31
+
5
32
  ## [0.3.8] - 2026-11-20
6
33
 
7
34
  ### Fixed
data/README.md CHANGED
@@ -263,6 +263,22 @@ dx --dx-terminal version # Force terminal detection
263
263
 
264
264
  The version lives in `lib/*/version.rb` (a `VERSION = "…"` constant), a bare `VERSION` file, or `version.rb`, looked for in that order. A bump that doesn't apply to the current version is refused with exit 1 and the file is left alone.
265
265
 
266
+ A project with more than one version can name further version files in `.dx.yml` (or `.dx/config.yml`) and address them by name:
267
+
268
+ ```yaml
269
+ # .dx.yml
270
+ versions:
271
+ spec: VERSION.SPEC
272
+ ```
273
+
274
+ ```bash
275
+ dx version spec # show
276
+ dx version spec bump pre # 2.0.0-alpha.0 → 2.0.0-alpha.1
277
+ dx version spec set 2.0.0-beta.0
278
+ ```
279
+
280
+ The unnamed commands keep working on the default file. If there is no default file, `dx version` lists the named versions.
281
+
266
282
  **Gem Packaging**
267
283
  - `dx gem build` - Build the gem
268
284
  - `dx gem install` - Build and install locally
@@ -117,6 +117,8 @@ def version_output(data)
117
117
  else
118
118
  text = if data[:old_version] && data[:new_version]
119
119
  "#{data[:old_version]} → #{data[:new_version]}"
120
+ elsif data[:versions]
121
+ data[:versions].map { |name, v| "#{name} #{v[:version]}" }.join("\n")
120
122
  else
121
123
  data[:version].to_s
122
124
  end
@@ -124,11 +126,132 @@ def version_output(data)
124
126
  end
125
127
  end
126
128
 
129
+ # --- Named version files ---
130
+ #
131
+ # A project can have more than one version: a specification and the
132
+ # implementation that follows it, say. Additional version files are named in
133
+ # the project's dx config (.dx.yml, or .dx/config.yml):
134
+ #
135
+ # versions:
136
+ # spec: VERSION.SPEC
137
+ #
138
+ # and addressed by putting the name first: `dx version spec bump pre`.
139
+ # The unnamed commands are unaffected and keep finding the project's default
140
+ # version file by convention (VERSION_FILE_PATTERNS).
141
+
142
+ # Words that already mean something right after `dx version`.
143
+ RESERVED_VERSION_NAMES = %w[bump set help].freeze
144
+
145
+ # { "spec" => "/abs/path/VERSION.SPEC" } from the project's config; {} if none.
146
+ def named_version_files(root)
147
+ return {} unless root
148
+
149
+ entries = Devex.load_config(root)["versions"]
150
+ return {} if entries.nil?
151
+
152
+ version_error("Config `versions:` must map names to file paths, e.g. `spec: VERSION.SPEC`") unless entries.is_a?(Hash)
153
+
154
+ entries.to_h do |name, path|
155
+ name = name.to_s
156
+ if RESERVED_VERSION_NAMES.include?(name)
157
+ version_error("Version name '#{name}' in config is reserved (#{RESERVED_VERSION_NAMES.join(', ')})")
158
+ end
159
+ version_error("Version name '#{name}' in config must be letters, digits, '-' or '_'") unless name.match?(/\A[A-Za-z][A-Za-z0-9_-]*\z/)
160
+ version_error("Version '#{name}' in config needs a file path") unless path.is_a?(String) && !path.strip.empty?
161
+
162
+ [name, File.expand_path(path, root)]
163
+ end
164
+ end
165
+
166
+ # The file for a configured name; fails if the name or the file is missing.
167
+ def named_version_file!(name)
168
+ version_error("Not in a project directory") unless cli.project_root
169
+
170
+ files = named_version_files(cli.project_root)
171
+ unless files.key?(name)
172
+ known = files.empty? ? "none are configured" : "configured: #{files.keys.join(', ')}"
173
+ version_error("Unknown version name '#{name}' (#{known}). " \
174
+ "Name version files under `versions:` in the project's dx config.")
175
+ end
176
+
177
+ file = files[name]
178
+ version_error("Version file for '#{name}' not found: #{file}") unless File.file?(file)
179
+ file
180
+ end
181
+
182
+ # The project's default (unnamed) version file.
183
+ def default_version_file!
184
+ version_error("Not in a project directory") unless cli.project_root
185
+
186
+ file = find_version_file(cli.project_root)
187
+ return file if file
188
+
189
+ names = named_version_files(cli.project_root).keys
190
+ hint = names.empty? ? "" : " This project names its versions: use `dx version <name> ...` (#{names.join(', ')})."
191
+ version_error("Could not find version file.#{hint}")
192
+ end
193
+
194
+ # `dx version set`, with the name included when there is one (for messages).
195
+ def explicit_set_command(name) = ["dx version", name, "set <version>"].compact.join(" ")
196
+
197
+ def bump_version_file(file, type, name: nil)
198
+ version_error("Invalid version type '#{type}'. Use: major, minor, patch, or pre") unless %w[major minor patch pre].include?(type)
199
+
200
+ old_version = read_version(file)
201
+ new_version = bump_version(old_version, type)
202
+ unless new_version
203
+ reason = if type == "pre"
204
+ "'pre' needs a prerelease version ending in a numeric counter (e.g. 2.0.0-alpha.0)"
205
+ else
206
+ "'#{type}' only applies to a plain MAJOR.MINOR.PATCH version"
207
+ end
208
+ version_error("Can't bump '#{old_version}': #{reason}. " \
209
+ "Use `#{explicit_set_command(name)}` to choose the next version explicitly. Nothing was changed.")
210
+ end
211
+
212
+ write_version(file, old_version, new_version)
213
+ version_output({ old_version: old_version, new_version: new_version, type: type, name: name, file: file }.compact)
214
+ end
215
+
216
+ def assign_version_file(file, version, name: nil)
217
+ unless version.match?(SETTABLE_VERSION)
218
+ version_error("Invalid version format '#{version}'. " \
219
+ "Use MAJOR.MINOR.PATCH, optionally with a prerelease tail (e.g. 2.0.0.pre or 2.0.0-rc.1)")
220
+ end
221
+
222
+ old_version = read_version(file)
223
+ write_version(file, old_version, version)
224
+ version_output({ old_version: old_version, new_version: version, name: name, file: file }.compact)
225
+ end
226
+
127
227
  # --- Main tool ---
128
228
 
129
229
  desc "Show or manage version"
130
230
 
231
+ long_desc <<~DESC
232
+ dx version Show the project's version
233
+ (all named versions, if there is no default file)
234
+ dx version bump TYPE Bump it (major, minor, patch, or pre)
235
+ dx version set VERSION Set it
236
+
237
+ A project with more than one version can name further version files in its
238
+ dx config (.dx.yml or .dx/config.yml):
239
+
240
+ versions:
241
+ spec: VERSION.SPEC
242
+
243
+ and address one by putting its name first:
244
+
245
+ dx version NAME Show that version
246
+ dx version NAME bump TYPE Bump it
247
+ dx version NAME set VERSION Set it
248
+ DESC
249
+
250
+ remaining_args :named, desc: "[NAME] [bump TYPE | set VERSION] for a version file named in the dx config"
251
+
131
252
  def run
253
+ return run_named(*named) if named && !named.empty?
254
+
132
255
  # Try project root first, then fall back to effective working directory.
133
256
  # This handles cases where a project exists but isn't yet recognized
134
257
  # (e.g., no .git, Gemfile, or other project markers).
@@ -144,9 +267,38 @@ def run
144
267
  end
145
268
  end
146
269
 
147
- version_data ||= { version: Devex::VERSION, source: "devex" }
270
+ return version_output(version_data) if version_data
271
+
272
+ # No default version file. If the project names its versions, show those;
273
+ # only a project with no version of its own gets devex's.
274
+ names = named_version_files(cli.project_root).keys
275
+ return version_output({ version: Devex::VERSION, source: "devex" }) if names.empty?
148
276
 
149
- version_output(version_data)
277
+ versions = names.to_h do |name|
278
+ file = named_version_file!(name)
279
+ [name, { version: read_version(file), file: file }]
280
+ end
281
+ version_output({ versions: versions, source: "project" })
282
+ end
283
+
284
+ # dx version NAME [bump TYPE | set VERSION]
285
+ def run_named(name, action = nil, value = nil, *extra)
286
+ file = named_version_file!(name)
287
+ usage = "Usage: dx version #{name} [bump <major|minor|patch|pre> | set <version>]"
288
+
289
+ version_error("Too many arguments. #{usage}") unless extra.empty?
290
+
291
+ case action
292
+ when nil then version_output({ version: read_version(file), source: "project", name: name, file: file })
293
+ when "bump"
294
+ version_error("Missing bump type. #{usage}") unless value
295
+ bump_version_file(file, value, name: name)
296
+ when "set"
297
+ version_error("Missing version. #{usage}") unless value
298
+ assign_version_file(file, value, name: name)
299
+ else
300
+ version_error("Unknown action '#{action}'. #{usage}")
301
+ end
150
302
  end
151
303
 
152
304
  # --- Subtools ---
@@ -166,59 +318,20 @@ tool "bump" do
166
318
  pre applies only to a prerelease that ends in a numeric counter. Anything
167
319
  else is refused rather than guessed at. To move between stages or to
168
320
  release (2.0.0-alpha.3 -> 2.0.0-beta.0 -> 2.0.0), use `dx version set`.
321
+
322
+ For a version file named in the dx config: dx version NAME bump TYPE
169
323
  DESC
170
324
 
171
325
  required_arg :type, desc: "Version component: major, minor, patch, or pre"
172
326
 
173
- def run
174
- version_error("Invalid version type '#{type}'. Use: major, minor, patch, or pre") unless %w[major minor patch pre].include?(type)
175
-
176
- version_error("Not in a project directory") unless cli.project_root
177
-
178
- version_file = find_version_file(cli.project_root)
179
- version_error("Could not find version file") unless version_file
180
-
181
- old_version = read_version(version_file)
182
- new_version = bump_version(old_version, type)
183
- unless new_version
184
- reason = if type == "pre"
185
- "'pre' needs a prerelease version ending in a numeric counter (e.g. 2.0.0-alpha.0)"
186
- else
187
- "'#{type}' only applies to a plain MAJOR.MINOR.PATCH version"
188
- end
189
- version_error("Can't bump '#{old_version}': #{reason}. " \
190
- "Use `dx version set <version>` to choose the next version explicitly. Nothing was changed.")
191
- end
192
-
193
- write_version(version_file, old_version, new_version)
194
-
195
- version_output(
196
- { old_version: old_version, new_version: new_version, type: type, file: version_file }
197
- )
198
- end
327
+ def run = bump_version_file(default_version_file!, type)
199
328
  end
200
329
 
201
330
  tool "set" do
202
331
  desc "Set version to a specific value"
332
+ long_desc "For a version file named in the dx config: dx version NAME set VERSION"
203
333
 
204
334
  required_arg :version, desc: "Version string (e.g., 1.0.0, 2.0.0.pre, 2.0.0-rc.1)"
205
335
 
206
- def run
207
- unless version.match?(SETTABLE_VERSION)
208
- version_error("Invalid version format '#{version}'. " \
209
- "Use MAJOR.MINOR.PATCH, optionally with a prerelease tail (e.g. 2.0.0.pre or 2.0.0-rc.1)")
210
- end
211
-
212
- version_error("Not in a project directory") unless cli.project_root
213
-
214
- version_file = find_version_file(cli.project_root)
215
- version_error("Could not find version file") unless version_file
216
-
217
- old_version = read_version(version_file)
218
- write_version(version_file, old_version, version)
219
-
220
- version_output(
221
- { old_version: old_version, new_version: version, file: version_file }
222
- )
223
- end
336
+ def run = assign_version_file(default_version_file!, version)
224
337
  end
data/lib/devex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devex
4
- VERSION = "0.3.8"
4
+ VERSION = "0.3.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph A Wecker