Amend the Trigger to parse options and switches
- -arg=value sets arg to value
- -arg sets arg to true
- -arg! sets arg to false
Options must be placed at the start of the arguments (directly after the trigger), as soon an argument starts without a dash, options parsing stops.
The prefix sign is - but for "compatibility" we will also match "--" and iOS safe "—".
!trigger -format=md arg1 arg2 arg3 # => %{options: %{"format" => "md", args: ["arg1", ...]} !trigger -hello world -deep deep # => %{options: %{"hello" => true, args: ["world", "-deep", ...]}
As the options is very plugin-specific and may eat text and break behavior, Options expansion should be performed before delivering the option to the plugin. The plugin should disclose the options it can when subscribing
{:ok, _} = Registry.register(IRC.PubSub, "trigger:something", [plugin: __MODULE__, trigger_options: %{ :opt1 => %{type: "string", default: nil}, :opt2 => %{type: "boolean", default: true}, … } )
Expansion should also be performed manually by calling IRC.Trigger.expand_options(trigger, options_schema).