At my work we build a lot of mix tasks for backfills and other maintenance tasks. Even with OptionParser
we seem to copy a lot of boilerplate between tasks. I’m wondering if folks would prefer a more batteries-included solution for building mix tasks, maybe even a domain-specific language for declaring options and such.
I’ve built a library called Executive, not published on Hex, and I’m looking for feedback on whether folks would use something like it (is there already something like it I’m missing?) or anything y’all would change.
It provides a mix task for generating mix tasks:
mix executive.gen.task my_object.do_something --uuid id --required \
--string cursor --datetime after --pos-integer batch_size --start-application
Running that task would generate a mix task that could get called as
mix my_object.do_something --id a7cde5bd-3878-42f9-b439-d49fd4ba37f9 \
--cursor b219859c98bb --after 2024-01-15T12:34:56Z --batch-size 500
Inside the mix task, you declare a bunch of options like this:
@optdoc "whether you want a or b or c"
option :my_option, {:enum, [:a, :b, :c]}
And Executive implements c:Mix.Task.run/1
, parses the options assertively, and calls c:Executive.Task.run/2
with the parsed options. But since the options are declared, it can also build docs and types and such for the task.