Format files from the command line
Aqua can format your code according to the configured code style settings. You can also apply your code style formatting to the specified files from the command line.
The command-line formatter launches an instance of Aqua in the background and applies the formatting. It will not work if another instance of Aqua is already running. In this case, you can perform code style formatting from the running instance. Use the command-line formatter for automated regular maintenance of a large codebase with many contributors to ensure a consistent coding style.
To be able to format files, install and enable plugins with support for the corresponding file types in Aqua (for example, the Shell Script plugin to format shell script files).
You can find the executable for running Aqua in the installation directory under bin. To use this executable as the command-line launcher, add it to your system PATH
as described in Command-line interface.
- Syntax
- aqua64.exe format [<options>] <path ...>
- Examples
Format two specific files from the C:\Data\src directory using the default code style settings:
aqua64.exe format -allowDefaults C:\Data\src\hello.html C:\Data\src\world.htmlRecursively format all files in the C:\Data\src directory including all subdirectories using the default code style settings:
aqua64.exe format -allowDefaults -r C:\Data\srcNon-recursively format all the .xml and .html files in the C:\Data\src directory using code style settings from C:\Data\settings.xml:
aqua64.exe format -s C:\Data\settings.xml -m *.xml,*.html C:\Data\src
Aqua includes a script for running the command-line code formatter. By default, it is located in the application package: Aqua.app/Contents/bin/format.sh
- Syntax
- ./format.sh [<options>] <path ...>
- Examples
Format two specific files from the ~/Data/src directory using the default code style settings:
./format.sh -allowDefaults ~/Data/src/hello.html ~/Data/src/world.htmlRecursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:
./format.sh -allowDefaults -r ~/Data/srcNon-recursively format all the .xml and .html files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:
./format.sh -s ~/Data/settings.xml -m *.xml,*.html ~/Data/src
You can find the script for running Aqua in the installation directory under bin. To use this script as the command-line launcher, add it to your system PATH
as described in Command-line interface.
- Syntax
- aqua.sh format [<options>] <path ...>
- Examples
Format two specific files from the ~/Data/src directory using the default code style settings:
aqua.sh format -allowDefaults ~/Data/src/hello.html ~/Data/src/world.htmlRecursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:
aqua.sh format -allowDefaults -r ~/Data/srcNon-recursively format all the .xml and .html files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:
aqua.sh format -s ~/Data/settings.xml -m *.xml,*.html ~/Data/src
Options
Option | Description |
---|---|
| Show the help message and quit. |
| Specify a comma-separated list of file masks that define the files to be processed. You can use the |
| Process specified directories recursively. |
| Specify the code style settings file to use for formatting. This can be one of the following:
The formatter also looks for .editorconfig files in the parent directories and applies them for formatting on top of the Aqua code style settings. In this case, if formatting settings from EditorConfig overlap with the settings from your code style scheme, Aqua will use the settings from EditorConfig. The remaining settings will be taken from your code style scheme. For more information, refer to EditorConfig. If this option is not specified, the file will be skipped. If there is a project in one of the parent folders, its settings will be used implicitly as well as EditorConfig. |
| Use the default code style settings when the code style is not defined for a file or a group of files: when |
| Preserve encoding and enforce the charset for reading and writing source files, for example: This option is useful if the command-line formatter cannot correctly process special letters in a source file. |
| Run the formatter in the validation mode. The formatter will perform the same formatting operations in memory and will exit with a non-zero status in case any of the formatted files differs from the original one. |