MobDev.TaskHelp (mob_dev v0.5.2)

Copy Markdown View Source

Helpers for --help / -h handling in mob_dev Mix tasks.

Mix has mix help <task> built in (reads the task module's @moduledoc), but users from outside the Elixir ecosystem expect <command> --help to work too. This module gives each task a one-line opt-in:

def run(args) do
  if MobDev.TaskHelp.help_requested?(args) do
    MobDev.TaskHelp.print_module_help(__MODULE__)
  else
    # normal flow…
  end
end

Public API is intentionally tiny — two predicates and a printer — so a future change to where @moduledoc is stored (or how it gets rendered) only ripples through one file.

Summary

Functions

True when argv contains --help or -h as a standalone arg.

Prints task_module's @moduledoc to stdout.

Functions

help_requested?(argv)

@spec help_requested?([String.t()]) :: boolean()

True when argv contains --help or -h as a standalone arg.

iex> MobDev.TaskHelp.help_requested?(["--help"])
true

iex> MobDev.TaskHelp.help_requested?(["-h"])
true

iex> MobDev.TaskHelp.help_requested?(["--device", "foo"])
false

iex> MobDev.TaskHelp.help_requested?([])
false