HelpfulOptions (helpful_options v0.1.0)

A project-specific command-line option parser

Summary

Functions

Parses command arguments, returns an error if required arguments are not supplied and sets the logging level

Functions

Link to this function

run(args, options \\ [])

Parses command arguments, returns an error if required arguments are not supplied and sets the logging level

iex> HelpfulOptions.run(["--foo", "hi"], switches: [foo: %{type: :string}]) {:ok, %{foo: "hi"}, []}

iex> HelpfulOptions.run(["-f", "hi"], switches: [foo: %{type: :string}], aliases: [f: :foo]) {:ok, %{foo: "hi"}, []}

iex> HelpfulOptions.run(["--bar", "hi"], switches: [foo: %{type: :string}])

iex> HelpfulOptions.run(["non-switch"], remaining: 1) {:ok, %{}, ["non-switch"]}

iex> HelpfulOptions.run(["pizza"])

iex> HelpfulOptions.run(["first", "second"], remaining: 2..3) {:ok, %{}, ["first", "second"]}

iex> HelpfulOptions.run(["first"], remaining: 2)

iex> HelpfulOptions.run(["first"], remaining: 2..3)

iex> HelpfulOptions.help([foo: %{type: :boolean}]) "Options:\n --foo Optional parameter"

iex> HelpfulOptions.help([foo: %{type: :string}]) "Options:\n --foo=FOO Optional parameter"

iex> HelpfulOptions.help([foo: %{type: :string, required: true}]) "Options:\n --foo=FOO Required"

iex> HelpfulOptions.help([foo: %{type: :boolean, description: "Frobnicate"}]) "Options:\n --foo Frobnicate"

iex> HelpfulOptions.help([foo: %{type: :string, description: "Frobnicate"}]) "Options:\n --foo=FOO Frobnicate"

iex> HelpfulOptions.help([foo: %{type: :string, description: "Frobnicate", required: true}]) "Options:\n --foo=FOO Frobnicate. Required"