Git.Commands.Var (git v0.6.1)

Copy Markdown View Source

Implements the Git.Command behaviour for git var.

Two modes are supported:

  • list mode (git var -l) parses the NAME=value lines into a map
  • single-variable mode (git var <NAME>) returns the trimmed value string

Set :name to look up a single variable; leave it nil to list all.

Summary

Functions

Returns the argument list for git var.

Parses the output of git var.

Types

t()

@type t() :: %Git.Commands.Var{name: String.t() | nil}

Functions

args(var)

@spec args(t()) :: [String.t()]

Returns the argument list for git var.

Examples

iex> Git.Commands.Var.args(%Git.Commands.Var{})
["var", "-l"]

iex> Git.Commands.Var.args(%Git.Commands.Var{name: "GIT_EDITOR"})
["var", "GIT_EDITOR"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, map() | String.t()} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git var.

In list mode, returns {:ok, map} mapping each variable name to its value. In single-variable mode, returns {:ok, value} with the trimmed string. On a non-zero exit code, returns {:error, {stdout, exit_code}}.