Skip to main content

CLI Reference

Synopsis

dfmt [options]                                format all included files
dfmt <file-or-dir> [options] format subset of included files
dfmt --dialect <dialect> <file> [options] yolo mode (no config file)
dfmt --changed-since <ref> [options] format files changed since git ref
dfmt --model <name> [options] format specific dbt model
dfmt --init [dialect] create .dfmt.json

Modes

Config mode (default)

Requires a .dfmt.json file, found by walking up from the current directory (or target path). The config provides the dialect, format options, and include/exclude patterns that determine which files to format.

Running dfmt with no arguments formats all files matching the include/exclude patterns.

Running dfmt <path> formats files under <path> that match the patterns.

Yolo mode

When no .dfmt.json exists, --dialect is required:

dfmt --dialect snowflake query.sql
dfmt --dialect bigquery queries/

In yolo mode, all .sql files under the target are formatted.

Options

Core

FlagDescription
--writeWrite formatted output back to files (only if changed)
--checkExit 1 if any file needs formatting. For CI pipelines.
--init [dialect]Create .dfmt.json in the current directory

File selection

FlagDescription
--dialect <dialect>Set dialect explicitly. Required in yolo mode.
--model <name>Format a specific dbt model by name
--changed-since <ref>Format only .sql files changed since a git ref (branch, tag, or SHA)
--no-jinjaFormat as plain SQL even if a dbt project is detected

Shorthand

FlagDescription
--uppercaseUppercase keywords (equivalent to --keyword-case upper)
--lowercaseLowercase keywords
--leading-commasLeading comma style
--indent NIndent width (spaces)
--width NMax line width

Format options

All format options from .dfmt.json can also be set via CLI flags. CLI flags override config file values.

FlagValuesDefault
--keyword-caseupper, lower, preservelower
--identifier-caseupper, lower, preservepreserve
--function-caseupper, lower, preservelower
--data-type-caseupper, lower, preservelower
--max-line-widthinteger80
--indent-widthinteger4
--comma-styletrailing, leadingtrailing
--clause-layoutindented, adaptiveindented
--sibling-layoutstacked, consistent, packstacked
--short-statements-one-linebooleantrue
--clarify-structurebooleanfalse
--blank-line-between-ctesbooleanfalse
--align-tokentoken to align (e.g., AS)none

Dialects

ansi, bigquery, postgres, duckdb, spark, databricks, snowflake, oracle, db2, tsql, mariadb, presto, trino, redshift, sqlite

Resolution Order

  1. Dialect: --dialect flag > .dfmt.json dialect > dbt adapter type > ansi
  2. Format options: dialect defaults > .dfmt.json overrides > CLI flag overrides
  3. Files: .dfmt.json include/exclude patterns > target path filter > --changed-since filter

Exit Codes

CodeMeaning
0Success (or --check found no changes needed)
1Error, or --check found files that need formatting