View Source CLIX.Spec (clix v0.1.0)

The spec builder.

A spec is the basis for parsing, feedback generation, etc.

Summary

Types

The name of a positional argument.

The parsing spec of positional argument.

The name of a command.

The parsing spec of a command.

Custom type.

The number of arguments that should be consumed.

The name of an optional argument.

The parsing spec of optional argument.

t()

The spec.

The type which the argument will be parsed as.

Functions

Builds a spec from raw spec.

Types

action()

@type action() :: :store | :count | :append

arg_name()

@type arg_name() :: atom()

The name of a positional argument.

arg_spec()

@type arg_spec() :: %{
  optional(:type) => type(),
  optional(:nargs) => nargs(),
  optional(:default) => any(),
  optional(:value_name) => value_name(),
  optional(:help) => String.t() | nil
}

The parsing spec of positional argument.

cmd_name()

@type cmd_name() :: atom()

The name of a command.

The top-level cmd_name is the program name. If you name your CLI app as example, then you should set the top-level cmd_name as :example.

cmd_spec()

@type cmd_spec() :: %{
  help: String.t() | nil,
  summary: String.t() | nil,
  description: String.t() | nil,
  cmds: [{cmd_name(), cmd_spec()}],
  args: [{arg_name(), arg_spec()}],
  opts: [{opt_name(), opt_spec()}],
  epilogue: String.t() | nil
}

The parsing spec of a command.

If the :help option isn't set, it will default to the value of :summary option.

custom_type()

@type custom_type() ::
  {:custom,
   (raw_value :: String.t() ->
      {:ok, value :: term()} | {:error, reason :: String.t()})}

Custom type.

nargs()

@type nargs() :: nil | :"?" | :* | :+

The number of arguments that should be consumed.

  • nil - consume one argument.
  • :"?" - consume zero or one argument.
  • :* - consume zero or more arguments.
  • :+ - consume one or more arguments.

opt_name()

@type opt_name() :: atom()

The name of an optional argument.

opt_spec()

@type opt_spec() :: %{
  optional(:short) => String.t() | nil,
  optional(:long) => String.t() | nil,
  optional(:type) => type(),
  optional(:action) => action(),
  optional(:default) => any(),
  optional(:value_name) => value_name(),
  optional(:help) => String.t() | nil
}

The parsing spec of optional argument.

t()

@type t() :: {cmd_name(), cmd_spec()}

The spec.

type()

@type type() :: :string | :boolean | :integer | :float | custom_type()

The type which the argument will be parsed as.

value_name()

@type value_name() :: String.t() | nil

Functions

new(arg)

@spec new(raw_spec :: {cmd_name(), cmd_spec()}) :: t()

Builds a spec from raw spec.

It will cast and validate the raw spec.