Page MenuHomePhabricator

Nola | IRC.Trigger: Support options/switches
Open, HighPublicFEATURE


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).

Event Timeline

href triaged this task as High priority.Dec 11 2022, 3:52 AM
href created this task.
href updated the task description. (Show Details)
href updated the task description. (Show Details)
href shifted this object from the Restricted Space space to the S6 Nola space.Dec 15 2022, 4:36 AM
href changed the visibility from "All Users" to "Public (No Login Required)".
href changed the edit policy from "All Users" to "Nola Devs (Project)".