lux-hammer 0.3.9 → 0.3.10
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/README.md +43 -7
- data/lib/hammer/command.rb +29 -0
- data/lib/lux-hammer.rb +2 -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: 81af43fc44619384d2b62f58e7d3178a1b6edb22cbb1ef4e836b73e2ee469913
|
|
4
|
+
data.tar.gz: 47d012b5e54d1e8df3441de01eeaee3e3267f71c4ac8545b80f413d419bd3fc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d1dd7d495b96a6f7023601427dadcd492e593934c6407eb48dcb7c53fea26e33ea44ec40ef3a69856199fa75dd9d6278a8d32b14cbd4733b692dbbfe662f97ee
|
|
7
|
+
data.tar.gz: 2a9b223844fd645a79403c653a2bf25be28ba5654eef8562738b2f3768b0a72bddfd8b5ceb3dfe68ac7c583ecaaefc18fcee4d64f3f47964a93ff8f12b0fb586
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.10
|
data/README.md
CHANGED
|
@@ -946,6 +946,41 @@ Hammer.run ARGV do
|
|
|
946
946
|
end
|
|
947
947
|
```
|
|
948
948
|
|
|
949
|
+
### `#!/usr/bin/env hammer` (single-file scripts)
|
|
950
|
+
|
|
951
|
+
For a one-off CLI that lives as a single executable file, point the
|
|
952
|
+
shebang straight at `hammer` - no `require`, no boilerplate:
|
|
953
|
+
|
|
954
|
+
```ruby
|
|
955
|
+
#!/usr/bin/env hammer
|
|
956
|
+
# desc: tiny greeter
|
|
957
|
+
|
|
958
|
+
task :hello do
|
|
959
|
+
desc 'say hi'
|
|
960
|
+
opt :loud, type: :boolean, alias: :l
|
|
961
|
+
proc do |opts|
|
|
962
|
+
msg = "hello #{opts[:args].first || 'world'}"
|
|
963
|
+
say.cyan(opts[:loud] ? msg.upcase : msg)
|
|
964
|
+
end
|
|
965
|
+
end
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
```sh
|
|
969
|
+
$ chmod +x greet
|
|
970
|
+
$ ./greet hello dino -l
|
|
971
|
+
HELLO DINO
|
|
972
|
+
$ ./greet --help
|
|
973
|
+
Usage: greet COMMAND [ARGS]
|
|
974
|
+
...
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
The file body is plain Hammerfile DSL (`task`, `namespace`, `before`,
|
|
978
|
+
`load`). `hammer` detects the shebang, evaluates the script as a
|
|
979
|
+
self-contained CLI, and uses the script's basename as the program name
|
|
980
|
+
in help - so `./greet --help` reads "Usage: greet ..." rather than
|
|
981
|
+
"Usage: hammer ...". The current working directory is left alone, so
|
|
982
|
+
relative paths inside the script resolve where the user ran it.
|
|
983
|
+
|
|
949
984
|
## Complete example (every feature)
|
|
950
985
|
|
|
951
986
|
```ruby
|
|
@@ -1192,21 +1227,19 @@ few small things that have been bugging me about both for years.
|
|
|
1192
1227
|
|
|
1193
1228
|
| | Thor | hammer |
|
|
1194
1229
|
|-|-|-|
|
|
1195
|
-
| Lines of code | ~6,000 | ~400 |
|
|
1196
1230
|
| Runtime deps | a few | zero |
|
|
1197
|
-
| Root constants | `Thor`, `Thor::Group`, `Thor::Shell`, `Thor::Actions`, ... | just `Hammer` |
|
|
1198
1231
|
| Command DSL | `desc 'usage', 'help'` + `method_option` + `def name(arg)` | `task :name do ... proc do \|opts\| end end` (or classic `desc` + `def`) |
|
|
1199
1232
|
| Opts container | `Thor::CoreExt::HashWithIndifferentAccess` | plain `Hash` with symbol keys |
|
|
1200
1233
|
| Positional args | method positional params + `method_option`, two parallel systems | declared-order opts fill from positional, single system |
|
|
1201
1234
|
| Sub-namespaces | `register SubClass, 'name', '...'` (inheritance ceremony) | `namespace :name do ... end` (no classes needed) |
|
|
1235
|
+
| Command aliases | none (workarounds via `map`) | `alt :s, :srv` |
|
|
1236
|
+
| Pre-hooks | none built-in | `before { ... }` per scope, `needs :env` per command |
|
|
1237
|
+
| Chained dispatch | no | `hammer build + deploy + notify` |
|
|
1202
1238
|
| Cross-invoke | `invoke 'name', [args], opts` | `hammer :name, **opts` (looks like a method call) |
|
|
1203
1239
|
| Inline CLI | class only | class DSL **or** `Hammer.run do ... end` block DSL **or** a `Hammerfile` |
|
|
1204
1240
|
|
|
1205
1241
|
**What hammer does better and why:**
|
|
1206
1242
|
|
|
1207
|
-
* **One root constant.** Thor exposes `Thor`, `Thor::Group`, `Thor::Shell`,
|
|
1208
|
-
`Thor::Actions` at the top level - Bundler had to vendor its own copy at
|
|
1209
|
-
`Bundler::Thor` to avoid clashes. Hammer is just `Hammer`.
|
|
1210
1243
|
* **The opts hash is just a Hash.** Symbol keys, always. No magic accessor
|
|
1211
1244
|
object to remember, no string-vs-symbol confusion, no method_missing.
|
|
1212
1245
|
* **Positional args fill opts in declaration order.** Thor either forces
|
|
@@ -1225,15 +1258,18 @@ few small things that have been bugging me about both for years.
|
|
|
1225
1258
|
| | Rake | hammer |
|
|
1226
1259
|
|-|-|-|
|
|
1227
1260
|
| Primary use case | build/task automation with file deps | general CLIs |
|
|
1228
|
-
| Task file | `Rakefile` | `Hammerfile` |
|
|
1261
|
+
| Task file | `Rakefile` | `Hammerfile` (walks up parent dirs) |
|
|
1229
1262
|
| Namespacing | colon paths (`db:migrate`) | colon paths (`db:migrate`) - parity |
|
|
1230
1263
|
| Per-task options | `task[a,b,c]` positional only | typed `opt`s with flags, aliases, defaults, required |
|
|
1231
1264
|
| Help | `rake -T` (plain list) | bare `hammer` lists everything grouped by namespace; `hammer X -h` for per-command help with examples and defaults |
|
|
1232
1265
|
| Cross-invoke | `Rake::Task['db:migrate'].invoke` | `hammer 'db:migrate'` |
|
|
1233
|
-
| Prerequisites | `task :build => [:clean, :compile]` (declarative DAG) |
|
|
1266
|
+
| Prerequisites | `task :build => [:clean, :compile]` (declarative DAG) | `needs :clean, :compile` (declarative, deduped across `+` chains) |
|
|
1267
|
+
| Pre-hooks | none built-in | `before { ... }` scoped to root or namespace |
|
|
1268
|
+
| Chained dispatch | no (multi-task argv runs sequentially, no per-task flags) | `hammer build prod -v + db:migrate --pretend + deploy` |
|
|
1234
1269
|
| File tasks | yes (mtime-based) | no |
|
|
1235
1270
|
| Aliases | none (workarounds via re-defined tasks) | `alt :short_name` |
|
|
1236
1271
|
| Split across files | `import 'other.rake'` | `load auto: true` (or explicit paths/globs) |
|
|
1272
|
+
| Shareable scripts | no | recipes (one-file CLIs installable as their own binary) |
|
|
1237
1273
|
|
|
1238
1274
|
**What hammer does better and why:**
|
|
1239
1275
|
|
data/lib/hammer/command.rb
CHANGED
|
@@ -39,5 +39,34 @@ class Hammer
|
|
|
39
39
|
name = name.to_s
|
|
40
40
|
name == @name || @alts.include?(name)
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
# Auto-assign a single-letter short alias (first letter of the opt
|
|
44
|
+
# name) to any opt that does not already declare one. Explicit
|
|
45
|
+
# aliases and `-h` are reserved first, so they always win. On
|
|
46
|
+
# collision the opt simply gets no short form - long flag still
|
|
47
|
+
# works. Idempotent.
|
|
48
|
+
def finalize!
|
|
49
|
+
return if @finalized
|
|
50
|
+
@finalized = true
|
|
51
|
+
|
|
52
|
+
claimed = ['-h']
|
|
53
|
+
@options.each do |o|
|
|
54
|
+
o.aliases.each { |a| claimed << a if short_flag?(a) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
@options.each do |o|
|
|
58
|
+
next if o.aliases.any? { |a| short_flag?(a) }
|
|
59
|
+
short = "-#{o.name.to_s[0]}"
|
|
60
|
+
next if claimed.include?(short)
|
|
61
|
+
o.aliases << short
|
|
62
|
+
claimed << short
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def short_flag?(switch)
|
|
69
|
+
switch.length == 2 && switch.start_with?('-') && switch[1] != '-'
|
|
70
|
+
end
|
|
42
71
|
end
|
|
43
72
|
end
|
data/lib/lux-hammer.rb
CHANGED
|
@@ -96,6 +96,7 @@ class Hammer
|
|
|
96
96
|
m = method_name
|
|
97
97
|
arity = instance_method(method_name).arity
|
|
98
98
|
cmd.handler = arity.zero? ? proc { send(m) } : proc { |opts| send(m, opts) }
|
|
99
|
+
cmd.finalize!
|
|
99
100
|
commands[cmd.name] = cmd
|
|
100
101
|
|
|
101
102
|
@pending_desc = nil
|
|
@@ -168,6 +169,7 @@ class Hammer
|
|
|
168
169
|
warn_redefinition('task', cmd.name, prev.location, cmd.location)
|
|
169
170
|
end
|
|
170
171
|
|
|
172
|
+
cmd.finalize!
|
|
171
173
|
commands[cmd.name] = cmd
|
|
172
174
|
|
|
173
175
|
# `task` ignores pending class-level state, but clear it so a
|
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.10
|
|
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-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|