# marmot fmt (/docs/commands/fmt)

<!-- Generated by scripts/gen.mjs from `marmot fmt --help` and scripts/commands.mjs. Do not edit by hand. -->

Format the Go files of the named packages, files or dir/... trees the way goimports does: gofmt layout, missing imports added, unused imports removed. Files are rewritten in place and listed, like go fmt. -l only lists, -d prints a diff, -check exits 1 when a file is not formatted.

```text title="Usage"
marmot fmt [files or packages] [flags]
```

## Examples [#examples]

```sh
marmot fmt
marmot fmt ./...
marmot fmt -d main.go
marmot fmt -check ./...
```

`marmot fmt` formats the files `go fmt` would: those of the packages' directories, leaving out
`testdata` and directories that start with `_` or `.`. It is the `fmt` check of
[marmot check](/docs/commands/check), so the two never disagree.

## Flags [#flags]

Flags take one dash or two: `-release` and `--release` are the same.

| Flag | Meaning |
| --- | --- |
| `-check` | change nothing; exit 1 if a file is not formatted |
| `-color string` | color in human output: auto, always or never (NO_COLOR turns auto off) (default "auto") |
| `-d` | print a diff of the changes instead of writing them |
| `-json` | machine readable output: JSON Lines on stderr (also $MARMOT_OUTPUT=json, and the default under coding agents) |
| `-l` | only list the files that would change |

## Full help [#full-help]

```text title="marmot fmt --help"
Format the Go files of the named packages, files or dir/... trees the way goimports does: gofmt layout, missing imports added, unused imports removed. Files are rewritten in place and listed, like go fmt. -l only lists, -d prints a diff, -check exits 1 when a file is not formatted.

Usage:
  marmot fmt [files or packages] [flags]

Examples:
marmot fmt
marmot fmt ./...
marmot fmt -d main.go
marmot fmt -check ./...

Flags:
      --check          change nothing; exit 1 if a file is not formatted
      --color string   color in human output: auto, always or never (NO_COLOR turns auto off) (default "auto")
      --d              print a diff of the changes instead of writing them
  -h, --help           help for fmt
      --json           machine readable output: JSON Lines on stderr (also $MARMOT_OUTPUT=json, and the default under coding agents)
      --l              only list the files that would change
```