# CLI
你可以不帶任何參數的使用 CLI 腳本來運行 Prettier 去查看其選項。
如果你想格式化具體的某一文件,可以使用 `--write`。你可能為了以防萬一,想在你提交代碼之前做點什么。
```shell
prettier [opts] [filename ...]
```
實際操作中,它可能是這樣:
```shell
prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js"
```
不要忘記 globs 周圍的引號!這個引號是為了跨平臺時候,確保 Prettier 擴展了 globs 而不是你的 shell,它使用了 [glob](https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer) 語法模塊。
Prettier CLI 會忽略本地的 `node_modules` 目錄中文件,你可以使用 `--width-node-modules` 標記來退出此行為。
## --debug-check
---
如果你擔心 Prettier 會改變你的代碼正確性,可以在命令上加上 `--debug-check`。如果它檢測到代碼的正確性可能被更改,它會打印一個錯誤信息出來。請注意,`--write` 不能與 `--debug-check` 一起使用。
## --find-config-path 和 --config
---
如果你反復用 `prettier` 格式化同一個文件,你可能會因為其嘗試查找[配置文件](https://prettier.io/docs/en/configuration.html)而產生一點性能問題。為了跳過這一步,你可能需要告訴 prettier 只查找一次配置文件,并在以后重復使用。
```shell
prettier --find-config-path ./my/file.js
./my/.prettierrc
```
你可以通過 `--config` 來提供配置文件目錄:
```shell
prettier --config ./my/.prettierrc --write ./my/file.js
```
如果你的配置文件放在 Prettier 無法找到的位置,比如 `config/` 目錄,你也可以通過 `--config` 來找到它。
如果你沒有配置文件,或者配置文件已存在,但是你想忽略它,你可以通過 `--no-config` 來替代它。
## --ignore-path
---
路徑下存在一個描述忽略文件模式的文件。默認情況下,prettier 會去查找 `./.prettierignore` 文件。
## --require-pragma
---
## --insert-pragma
---
## --list-different
---
另一個有用的標記是 `--list-different` (或 `-l`),它會打印于 Prettier 的格式不同的文件名稱。如果他們之間有差異,那么便會輸出錯誤,這對于 CI 腳本十分有用。
## --no-config
---
不查找配置文件,默認使用。
## --config-precedence
---
定義如何結合 CLI 選項來處理配置文件
**cli-override (default)**
CLI 選項優先于配置文件
**file-override**
配置文件優先于 CLI 選項
**prefer-file**
如果找到配置文件,那么便使用它,忽略其他 CLI 選項。如果沒有找到,那么 CLI 選項便會正常使用。此選項增加了編輯器集成,允許用戶定義其默認配置,但希望遵守項目的特定配置。
## --no-editorconfig
---
當解析配置時,不會考慮 .editorconfig,詳細請看 [`prettier.resolveConfig` docs](https://prettier.io/docs/en/api.html)。
## --with-node-modules
---
Prettier CLI 會忽略位于 `node_modules` 目錄下的文件,可以通過 `--with-node-modules` 來退出此行為。
## --write
---
重寫目錄下所有已處理的文件,這與 `eslint --fix` 的工作流程差不多。
## --loglevel
---
改變 CLI 的日志級別。合法的選項如下:
+ `error`
+ `warn`
+ `log` (default)
+ `debug`
+ `silent`
## --stdin-filepath
---