NBPR.BrPackage (NBPR v0.2.0)

Copy Markdown View Source

The macro every NBPR package uses.

Daemonless example

defmodule NBPR.Jq do
  use NBPR.BrPackage,
    version: 1,
    br_package: "jq",
    description: "Lightweight JSON processor",
    homepage: "https://jqlang.github.io/jq/",
    build_opts: [
      oniguruma: [
        type: :boolean,
        default: true,
        br_flag: "BR2_PACKAGE_JQ_ONIGURUMA",
        doc: "Enable Oniguruma regex support"
      ]
    ]
end

Daemon-bearing example

defmodule NBPR.Dnsmasq do
  use NBPR.BrPackage,
    version: 1,
    br_package: "dnsmasq",
    description: "Lightweight DHCP/DNS server",
    daemons: [
      dnsmasq: [
        path: "/usr/sbin/dnsmasq",
        opts: [
          config_file: [type: :string, required: true, flag: "--conf-file"],
          keep_in_foreground: [type: :boolean, default: true, flag: "--keep-in-foreground"]
        ]
      ]
    ]
end

Each declared daemon emits a nested module (NBPR.Dnsmasq.Dnsmasq above) with child_spec/1, start_link/1, and argv/1. Users add the daemon module to their own supervision tree.

Argv assembly

The default argv builder zips each runtime opt with its declared :flag: booleans emit the flag if true (nothing if false); other values emit [flag, to_string(value)]. For daemons whose argv has subcommands or positional arguments, override with argv_template: in the daemon spec — any MFA tuple {module, fun, extra_args} whose function returns a list of strings.

Summary

Functions

Default argv builder. Zips each opt with its :flag extension; booleans emit the flag-only form, other values emit [flag, to_string(value)], opts without a :flag mapping are dropped.

Functions

default_argv(validated_opts, opt_flags)

@spec default_argv(
  keyword(),
  %{required(atom()) => String.t()}
) :: [String.t()]

Default argv builder. Zips each opt with its :flag extension; booleans emit the flag-only form, other values emit [flag, to_string(value)], opts without a :flag mapping are dropped.