Format files from the command line
Apply code style formatting to specified files from the command line. To be able to format files, install and enable plugins with support for the corresponding file types in CLion (for example, the Shell Script plugin to format shell script files).
You can find the script for running CLion 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
- clion.bat format [<options>] <path ...>
- Examples
-
Format two specific files from the C:\Data\src directory using the default code style settings:
clion.bat format C:\Data\src\hello.cpp C:\Data\src\world.cppRecursively format all files in the C:\Data\src directory including all subdirectories using the default code style settings:
clion.bat format -r C:\Data\srcNon-recursively format all the .cpp and .h files in the C:\Data\src directory using code style settings from C:\Data\settings.xml:
clion.bat format -s C:\Data\settings.xml -m *.cpp,*.h C:\Data\src
By default, CLion does not provide a command-line launcher. For information about creating a launcher script for CLion, see Command-line interface.
- Syntax
- clion format [<options>] <path ...>
- Examples
-
Format two specific files from the ~/Data/src directory using the default code style settings:
clion format ~/Data/src/hello.cpp ~/Data/src/world.cppRecursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:
clion format -r ~/Data/srcNon-recursively format all the .cpp and .h files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:
clion format -s ~/Data/settings.xml -m *.cpp,*.h ~/Data/src
You can find the script for running CLion 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
- clion.sh format [<options>] <path ...>
- Examples
-
Format two specific files from the ~/Data/src directory using the default code style settings:
clion.sh format ~/Data/src/hello.cpp ~/Data/src/world.cppRecursively format all files in the ~/Data/src directory including all subdirectories using the default code style settings:
clion.sh format -r ~/Data/srcNon-recursively format all the .cpp and .h files in the ~/Data/src directory using code style settings from ~/Data/settings.xml:
clion.sh format -s ~/Data/settings.xml -m *.cpp,*.h ~/Data/src
Options
Option | Description |
---|---|
-h | Show the help message and quit. |
-m|-mask | Specify a comma-separated list of file masks that define the files to be processed. You can use the * (any string) and ? (any single character) wildcards. |
-r|-R | Process specified directories recursively. |
-s|-settings | Specify the code style settings file to use for formatting. This can be one of the following:
If this option is not specified, the default code style settings will be used. |