# `Minga.Command.Parser`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/command/parser.ex#L1)

Parser for Vim-style `:` command-line input.

Converts a raw string (without the leading `:`) into a structured
`t:parsed/0` value that the editor can act on.

## Supported commands

| Input            | Result                         |
|------------------|--------------------------------|
| `w`              | `{:save, []}`                  |
| `w!`             | `{:force_save, []}`            |
| `q`              | `{:quit, []}`                  |
| `q!`             | `{:force_quit, []}`            |
| `qa`             | `{:quit_all, []}`              |
| `qa!`            | `{:force_quit_all, []}`        |
| `wq`             | `{:save_quit, []}`             |
| `e <filename>`   | `{:edit, filename}`            |
| `e!`             | `{:force_edit, []}`            |
| `<number>`       | `{:goto_line, number}`         |
| anything else    | `{:unknown, original_string}`  |

# `parsed`

```elixir
@type parsed() ::
  {:save, []}
  | {:force_save, []}
  | {:quit, []}
  | {:force_quit, []}
  | {:quit_all, []}
  | {:force_quit_all, []}
  | {:save_quit, []}
  | {:save_quit_all, []}
  | {:edit, String.t()}
  | {:force_edit, []}
  | {:checktime, []}
  | {:new_buffer, []}
  | {:lsp_info, []}
  | {:extensions, []}
  | {:extension_update, []}
  | {:extension_update_all, []}
  | {:parser_restart, []}
  | {:agent_abort, []}
  | {:agent_new_session, []}
  | {:agent_set_provider, [String.t()]}
  | {:agent_set_model, [String.t()]}
  | {:agent_pick_model, []}
  | {:agent_cycle_model, []}
  | {:agent_cycle_thinking, []}
  | {:tool_install_named, [String.t()]}
  | {:tool_uninstall_named, [String.t()]}
  | {:tool_update_named, [String.t()]}
  | {:goto_line, pos_integer()}
  | {:set, atom()}
  | {:setglobal, atom()}
  | {:substitute, String.t(), String.t(), [substitute_flag()]}
  | {:rename, String.t()}
  | {:unknown, String.t()}
```

Structured result of parsing a command-line string.

* `{:save, []}` — write the current buffer to disk (`:w`)
* `{:force_save, []}` — force-write, skipping mtime check (`:w!`)
* `{:quit, []}` — close current tab or quit if last tab (`:q`)
* `{:force_quit, []}` — force close tab or quit without saving (`:q!`)
* `{:quit_all, []}` — quit the entire editor (`:qa`)
* `{:force_quit_all, []}` — force quit the entire editor (`:qa!`)
* `{:save_quit, []}` — save and close tab, or save and quit if last tab (`:wq`)
* `{:save_quit_all, []}` — save all buffers and quit (`:wqa`)
* `{:edit, filename}` — open a file (`:e filename`)
* `{:force_edit, []}` — reload current buffer from disk (`:e!`)
* `{:new_buffer, []}` — create a new empty buffer (`:new` / `:enew`)
* `{:goto_line, n}` — jump to line *n* (`:<number>`)
* `{:substitute, pattern, replacement, flags}` — `:%s/old/new/flags`
* `{:unknown, raw}` — unrecognised command

# `substitute_flag`

```elixir
@type substitute_flag() :: :global | :confirm
```

Flags for :%s substitution.

# `parse`

```elixir
@spec parse(String.t()) :: parsed()
```

Parses a command-line string (without the leading `:`) and returns a
`t:parsed/0` value.

## Examples

    iex> Minga.Command.Parser.parse("w")
    {:save, []}

    iex> Minga.Command.Parser.parse("q!")
    {:force_quit, []}

    iex> Minga.Command.Parser.parse("e README.md")
    {:edit, "README.md"}

    iex> Minga.Command.Parser.parse("42")
    {:goto_line, 42}

    iex> Minga.Command.Parser.parse("w!")
    {:force_save, []}

    iex> Minga.Command.Parser.parse("e!")
    {:force_edit, []}

    iex> Minga.Command.Parser.parse("xyz")
    {:unknown, "xyz"}

---

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