# `Git.Commands.Submodule`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/submodule.ex#L1)

Implements the `Git.Command` behaviour for `git submodule`.

Supports status (default), init, update, add, deinit, sync, summary,
set-branch, and set-url subcommands.

The `foreach` subcommand is intentionally not supported because it requires
an arbitrary shell command string, which does not fit the structured command
model and would introduce shell injection concerns.

# `t`

```elixir
@type t() :: %Git.Commands.Submodule{
  add_path: String.t() | nil,
  add_url: String.t() | nil,
  all: boolean(),
  branch: String.t() | nil,
  deinit: String.t() | nil,
  depth: non_neg_integer() | nil,
  force: boolean(),
  init: boolean(),
  merge: boolean(),
  name: String.t() | nil,
  path: String.t() | nil,
  quiet: boolean(),
  rebase: boolean(),
  recursive: boolean(),
  reference: String.t() | nil,
  remote: boolean(),
  set_branch: String.t() | nil,
  set_url: String.t() | nil,
  status: boolean(),
  summary: boolean(),
  sync: boolean(),
  update: boolean()
}
```

# `args`

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

Returns the argument list for `git submodule`.

- If `:add_url` is set, builds `git submodule add [options] <url> [<path>]`.
- If `:deinit` is set, builds `git submodule deinit [--force] [--all] <path>`.
- If `:init` is true, builds `git submodule init [<path>]`.
- If `:update` is true, builds `git submodule update [options] [<path>]`.
- If `:sync` is true, builds `git submodule sync [--recursive] [<path>]`.
- If `:summary` is true, builds `git submodule summary [<path>]`.
- If `:set_branch` is set, builds `git submodule set-branch -b <branch> <path>`.
- If `:set_url` is set, builds `git submodule set-url <path> <url>`.
- Otherwise, shows status with `git submodule status [--recursive] [<path>]`.

## Examples

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{})
    ["submodule", "status"]

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{init: true})
    ["submodule", "init"]

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{update: true, recursive: true})
    ["submodule", "update", "--recursive"]

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{add_url: "https://example.com/lib.git", add_path: "vendor/lib"})
    ["submodule", "add", "https://example.com/lib.git", "vendor/lib"]

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{deinit: "vendor/lib", force: true})
    ["submodule", "deinit", "--force", "vendor/lib"]

    iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{sync: true, recursive: true})
    ["submodule", "sync", "--recursive"]

# `parse_output`

```elixir
@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [Git.SubmoduleEntry.t()]}
  | {:ok, :done}
  | {:ok, String.t()}
  | {:error, {String.t(), non_neg_integer()}}
```

Parses the output of `git submodule`.

For status operations (exit 0), parses each line into a `Git.SubmoduleEntry`
struct. For mutation operations (exit 0), returns `{:ok, :done}`. For summary
operations (exit 0), returns `{:ok, stdout}` with the raw summary text.
On failure, returns `{:error, {stdout, exit_code}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
