# How-to guides

Recipes for one task each, for a reader who already knows what they want to do.

Each guide solves one task and assumes you have dmog installed, except the guides to the libraries, which start by adding one to a project. To learn dmog from the start, take the [tutorials](https://dmog.tabnas.dev/tutorials/) first. For every option a guide uses, see the [reference](https://dmog.tabnas.dev/reference/).

## Setting up

Install dmog, in whichever runtime you already use.

- [Install dmog](https://dmog.tabnas.dev/how-to/install.html): Install the dmog command with npm, Go, or Cargo, and check that it runs.

## Translating documents

Write a document of one format in another: all of it or part of it, reshaped on the way, and documents that cannot be streamed.

- [Translate a document to another format](https://dmog.tabnas.dev/how-to/translate-a-document.html): Write a file, or standard input, in another format, and save the result.
- [Translate part of a document](https://dmog.tabnas.dev/how-to/translate-part.html): Pick one value out of a document with --path and write only that value.
- [Name the key a document is written under](https://dmog.tabnas.dev/how-to/name-the-root.html): Choose the key --key wraps a document under, for a format whose root must be an object.
- [Translate a document that cannot be streamed](https://dmog.tabnas.dev/how-to/read-whole.html): Use --whole for a document with a repeated key or several YAML documents, which dmog cannot write as it reads.
- [Reshape a document while translating it](https://dmog.tabnas.dev/how-to/reshape-with-a-program.html): Run an alchemy program over the input with --with, and write what it returns in the target format.
- [Convert a grammar between ABNF, EBNF, and GBNF](https://dmog.tabnas.dev/how-to/convert-a-grammar.html): Write a grammar from one notation in another, and understand the refusals when a notation cannot say a rule.
- [Limit how much dmog writes](https://dmog.tabnas.dev/how-to/limit-output.html): Stop a translation or a program with --max-output-bytes once its output would pass a size you choose.

## Running programs

Check, format and explain an alchemy program, and run it over a document.

- [Run a program over a document](https://dmog.tabnas.dev/how-to/run-a-program.html): Run an alchemy program over a JSON document with dmog run, and choose how a table it returns is written.
- [Check and format a program](https://dmog.tabnas.dev/how-to/check-and-format.html): Find the mistakes in an alchemy program before it runs, and print it in canonical or layout form.
- [Find out what a program keeps in memory](https://dmog.tabnas.dev/how-to/explain-a-program.html): Read the plan report dmog explain prints, to learn how a program reads its input and what it holds while it runs.

## Scripting

Use dmog from a script: read its failures and its exit statuses.

- [Handle dmog's failures in a script](https://dmog.tabnas.dev/how-to/handle-failures.html): Tell success from failure by the exit status, read the failure object on standard error, and know when output was left behind.

## Using the libraries

Call dmog from a program of your own, in TypeScript, Go, or Rust.

- [Use the TypeScript library](https://dmog.tabnas.dev/how-to/use-the-typescript-library.html): Add @tabnas/dmog to a Node.js project, translate a string or a stream, run a program, read a failure, stop a run, and choose between the asynchronous and synchronous forms.
- [Use the Go library](https://dmog.tabnas.dev/how-to/use-the-go-library.html): Add the dmog module to a Go program, translate a string or a stream, run a program, read a failure, set a limit, and stop a run with its context.
- [Use the Rust library](https://dmog.tabnas.dev/how-to/use-the-rust-library.html): Add tabnas-dmog to a Rust project, translate a string or a stream, run a program, read a failure, and stop a run that is under way.
