2022-10-06 21:00:29 +00:00
|
|
|
---
|
|
|
|
layout: docs
|
|
|
|
page_title: 'Commands: fmt'
|
|
|
|
description: |
|
|
|
|
Rewrite Nomad config and job files to canonical format
|
|
|
|
---
|
|
|
|
|
|
|
|
# Command: fmt
|
|
|
|
|
|
|
|
The `fmt` commands check the syntax and rewrites Nomad configuration and jobspec
|
|
|
|
files to canonical format. It can be used to improve readability and enforce
|
|
|
|
consistency of style in Nomad files.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```plaintext
|
|
|
|
nomad fmt [flags] paths ...
|
|
|
|
```
|
|
|
|
|
|
|
|
Formats Nomad agent configuration and job file to a canonical format. If a path
|
|
|
|
is a directory, it will recursively format all files with .nomad and .hcl
|
|
|
|
extensions in the directory.
|
|
|
|
|
|
|
|
If you provide a single dash (-) as argument, fmt will read from standard input
|
|
|
|
(STDIN) and output the processed output to standard output (STDOUT).
|
|
|
|
|
|
|
|
## Format Options:
|
|
|
|
|
2023-02-15 19:06:31 +00:00
|
|
|
- `-check`: Check if the files are valid HCL files. If not, exit status of the
|
|
|
|
command will be 1 and the incorrect files will not be formatted. This flag
|
|
|
|
overrides any `-write` flag value.
|
|
|
|
- `-list`: List the files which contain formatting inconsistencies. Defaults to
|
|
|
|
`-list=true`.
|
|
|
|
- `-recursive`: Process files in subdirectories. By default only the given (or
|
|
|
|
current) directory is processed.
|
|
|
|
- `-write`: Overwrite the input files. Defaults to `-write=true`.
|
2022-10-06 21:00:29 +00:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```shell-session
|
2023-02-15 19:06:31 +00:00
|
|
|
$ cat agent.hcl
|
2022-10-06 21:00:29 +00:00
|
|
|
server {
|
|
|
|
enabled = true
|
|
|
|
bootstrap_expect = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
client {
|
|
|
|
enabled = true
|
|
|
|
}
|
2023-02-15 19:06:31 +00:00
|
|
|
```
|
2022-10-06 21:00:29 +00:00
|
|
|
|
2023-02-15 19:06:31 +00:00
|
|
|
```shell-session
|
2022-10-06 21:00:29 +00:00
|
|
|
$ nomad fmt
|
|
|
|
agent.hcl
|
2023-02-15 19:06:31 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```shell-session
|
|
|
|
$ cat agent.hcl
|
2022-10-06 21:00:29 +00:00
|
|
|
server {
|
|
|
|
enabled = true
|
|
|
|
bootstrap_expect = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
client {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
```
|