Module: Hammer::Builtins
- Defined in:
- lib/hammer/builtins.rb
Overview
Lazy-loaded “built-ins” attached under the reserved ‘self:` namespace of the `hammer` binary. Hosts management commands (recipes, AGENTS.md dump, self-update) that should not appear on every user-command run. `Hammer.cli` only calls `register` when argv shows the user is asking for help or invoking a `self:`-prefixed command.
Defined Under Namespace
Modules: Recipes
Class Method Summary collapse
-
.register(klass) ⇒ Object
Wire the ‘self:` namespace into `klass`.
Class Method Details
.register(klass) ⇒ Object
Wire the ‘self:` namespace into `klass`. Idempotent - safe to call twice; the second call replaces the existing subclass.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hammer/builtins.rb', line 12 def register(klass) Thread.current[:hammer_builtins_loading] = true klass.namespace(:self) do task :ai do desc 'Print AGENTS.md (AI-friendly Hammerfile authoring docs)' proc { Hammer.print_ai_help } end task :update do desc 'Update lux-hammer from github main (requires install.sh checkout)' proc { Hammer.self_update } end task :recipe do desc <<~TXT Manage recipes. First positional argument is the action. (no args) list all recipes install [NAME] [PATH] install stub. No PATH: print to stdout. With PATH: write + chmod +x. show NAME cat recipe source path NAME print recipe abs path edit NAME open recipe in $EDITOR run NAME [ARGS] run a recipe without installing its bin TXT example 'self:recipe' example 'self:recipe install srt ~/bin/srt # write + chmod in one shot' example 'self:recipe install srt > ~/bin/srt && chmod +x $_' example 'self:recipe show srt' example 'self:recipe run srt extract movie.mp4' example 'self:recipe run srt -- --help # -- forwards flags to the recipe' proc do |opts| action, name, *rest = opts[:args] Hammer::Builtins::Recipes.dispatch(action, name, rest) end end end ensure Thread.current[:hammer_builtins_loading] = nil end |