lux-hammer 0.3.5 → 0.3.6
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 +4 -4
- data/.version +1 -1
- data/lib/hammer/command.rb +1 -1
- data/lib/lux-hammer.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62eaadbe6e088375e7762d4b16050df8b17f3242a5e92bf611776ff58b3c3e91
|
|
4
|
+
data.tar.gz: 765045381a51f5e6cea55f8250ed0543ead5ba67f765241a3e8db3faa108d92b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9de3baba0031948bb5e11c37f282b6d8e0af7a33d703d69f4d6c7026473f1985207c186882a19c313454cdc6e0eea310a109f708a393b269e1c043695d4daf0d
|
|
7
|
+
data.tar.gz: ff7e9f42651d68b8ba7f3f649693fc66171dc758d9b98f3ff58859f16419ebbeee976bae4931b4d4008acaad9b7635f5250a24d6e2f49df823ce47ea5e882c46
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.6
|
data/lib/hammer/command.rb
CHANGED
|
@@ -2,7 +2,7 @@ class Hammer
|
|
|
2
2
|
# A single registered command on a Hammer class.
|
|
3
3
|
class Command
|
|
4
4
|
attr_reader :name, :desc, :options, :examples, :alts, :needs
|
|
5
|
-
attr_accessor :handler
|
|
5
|
+
attr_accessor :handler, :location, :prev_location
|
|
6
6
|
|
|
7
7
|
def initialize(name:, desc: '', handler: nil)
|
|
8
8
|
@name = name.to_s
|
data/lib/lux-hammer.rb
CHANGED
|
@@ -141,6 +141,7 @@ class Hammer
|
|
|
141
141
|
# lives at `opts[:args]`.
|
|
142
142
|
def task(name, &block)
|
|
143
143
|
cmd = Command.new(name: name.to_s)
|
|
144
|
+
cmd.location = source_location_of(block)
|
|
144
145
|
handler = CommandBuilder.new(cmd).instance_eval(&block)
|
|
145
146
|
unless handler.is_a?(Proc)
|
|
146
147
|
raise Error, <<~MSG
|
|
@@ -161,6 +162,12 @@ class Hammer
|
|
|
161
162
|
MSG
|
|
162
163
|
end
|
|
163
164
|
cmd.handler = handler
|
|
165
|
+
|
|
166
|
+
if (prev = commands[cmd.name])
|
|
167
|
+
cmd.prev_location = prev.location
|
|
168
|
+
warn_redefinition('task', cmd.name, prev.location, cmd.location)
|
|
169
|
+
end
|
|
170
|
+
|
|
164
171
|
commands[cmd.name] = cmd
|
|
165
172
|
|
|
166
173
|
# `task` ignores pending class-level state, but clear it so a
|
|
@@ -199,7 +206,14 @@ class Hammer
|
|
|
199
206
|
# "myapp ns:cmd" with the same prefix everywhere - and so the value
|
|
200
207
|
# captured pre-chdir (see `Hammer.cli`) survives into nested classes.
|
|
201
208
|
sub.instance_variable_set(:@program_name, program_name)
|
|
209
|
+
sub.instance_variable_set(:@location, source_location_of(block))
|
|
202
210
|
Hammer.with_target(sub) { sub.class_eval(&block) } if block
|
|
211
|
+
|
|
212
|
+
if (prev = @namespaces[name.to_s])
|
|
213
|
+
sub.instance_variable_set(:@prev_location, prev.instance_variable_get(:@location))
|
|
214
|
+
warn_redefinition('namespace', name.to_s, prev.instance_variable_get(:@location), sub.instance_variable_get(:@location))
|
|
215
|
+
end
|
|
216
|
+
|
|
203
217
|
@namespaces[name.to_s] = sub
|
|
204
218
|
end
|
|
205
219
|
|
|
@@ -236,6 +250,21 @@ class Hammer
|
|
|
236
250
|
@parent
|
|
237
251
|
end
|
|
238
252
|
|
|
253
|
+
# "file:line" of the block that defined a task/namespace. Falls back
|
|
254
|
+
# to "(unknown)" for blocks without a usable source_location (rare -
|
|
255
|
+
# built-in C-defined procs, eval'd blocks).
|
|
256
|
+
def source_location_of(block)
|
|
257
|
+
loc = block&.source_location
|
|
258
|
+
loc ? "#{loc[0]}:#{loc[1]}" : '(unknown)'
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Emit a yellow [hammer] warning on stderr when a task/namespace is
|
|
262
|
+
# redefined. Last write wins (commands[name] = cmd), but the prior
|
|
263
|
+
# location is captured so listings can tag the entry as `(redefined)`.
|
|
264
|
+
def warn_redefinition(kind, name, prev_loc, new_loc)
|
|
265
|
+
warn Shell.paint("[hammer] redefined #{kind} :#{name} - was #{prev_loc || '(unknown)'}, now #{new_loc || '(unknown)'}", :yellow)
|
|
266
|
+
end
|
|
267
|
+
|
|
239
268
|
# Root -> ... -> self. Used to gather `before` hooks for a command.
|
|
240
269
|
def ancestor_chain
|
|
241
270
|
chain = []
|
|
@@ -755,6 +784,7 @@ class Hammer
|
|
|
755
784
|
def emit_rows(rows, width)
|
|
756
785
|
rows.each do |full, c|
|
|
757
786
|
brief = c.alts.empty? ? c.brief : "#{c.brief} (alt: #{c.alts.join(', ')})"
|
|
787
|
+
brief = "#{brief} #{Shell.paint('(redefined)', :yellow)}" if c.prev_location
|
|
758
788
|
Shell.say " #{program_name} #{full.ljust(width)} # #{brief}"
|
|
759
789
|
end
|
|
760
790
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lux-hammer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dino Reic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|