AStyle Commands


Introduction to AStyle

AStyle (Artistic Style) is a versatile code formatting tool designed to automatically format source code files across various programming languages. It supports languages such as C, C++, C#, and Java, among others. AStyle ensures that code adheres to a consistent style, enhancing readability and maintainability in software projects.

By standardizing code formatting, AStyle simplifies collaboration among developers and improves code quality. It can be integrated into development workflows to enforce coding standards and reduce manual formatting efforts.

Installation of AStyle on Windows can be conveniently managed through Chocolatey, a popular package manager for Windows. Chocolatey streamlines the installation process, making it easy to set up and maintain AStyle across development environments.

Install Chocolatey (if not already installed)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Installs Chocolatey, a package manager for Windows, which facilitates the installation of various software packages, including AStyle.

Description:
  • Before installing AStyle using Chocolatey, ensure Chocolatey is installed on your system.
  • The command above sets the necessary execution policies and downloads the Chocolatey installation script from its official source.
Output: Chocolatey is installed and ready to use on your system.
Install AStyle using Chocolatey
choco install astyle
Installs AStyle (Artistic Style) using Chocolatey package manager on Windows.

Description:
  • choco install astyle installs AStyle and its dependencies via Chocolatey.
  • Chocolatey handles the download, installation, and management of AStyle, ensuring it is correctly set up for use.
Output: AStyle is installed and ready to use on your system.
Command 1:
astyle --recursive --suffix=none "*.c"
This command recursively formats all .c files in the current directory and its subdirectories using AStyle, without saving original files with a .orig extension.

Options Used:
  • --recursive: Processes files in subdirectories recursively.
  • --suffix=none: Specifies not to create backup files with a suffix.
  • "*.c": Matches all files with the .c extension for formatting.
Output: AStyle formats each .c file according to default settings or those specified in a configuration file, without creating .orig backup files due to the --suffix=none option.

Original Files: AStyle does not retain the original files; instead, it generates formatted copies without saving them with a .orig extension, thanks to the --suffix=none option.
Command 2:
astyle --options=C:\ProgramData\chocolatey\lib\astyle\tools\astyle-3.5.2-x64\file\astyle.ini --recursive "*.c"
Formats all .c files based on options defined in a configuration file (astyle.ini).

Options Used:
  • --options=C:\ProgramData\chocolatey\lib\astyle\tools\astyle-3.5.2-x64\file\astyle.ini: Specifies the path to the configuration file containing formatting options.
  • --recursive "*.c": Recursively formats all .c files in the current directory and its subdirectories.
Output: AStyle formats each .c file according to settings specified in astyle.ini.

Original Files: AStyle retains the original files and generates formatted copies. The original files are saved with a .orig extension.
Command 3:
astyle --style=allman --indent=spaces=4 example.c
Formats a specific file (example.c) using inline options.

Options Used:
  • --style=allman: Sets the brace style to "allman".
  • --indent=spaces=4: Sets indentation style to use 4 spaces.
  • example.c: Specifies the file to format.
Output: AStyle formats example.c according to specified options.

Original File: AStyle preserves the original example.c file and creates a formatted copy. The original file is saved with a .orig extension.
Command 4:
astyle --style=java --indent=tab --recursive "src/*.c"
Formats all .c files in a specific directory (src) using inline options.

Options Used:
  • --style=java: Sets the brace style to "java".
  • --indent=tab: Sets indentation style to use tabs.
  • --recursive "src/*.c": Recursively formats all .c files in the src directory.
Output: AStyle formats .c files in src and its subdirectories as per specified options.

Original Files: AStyle keeps the original files intact and generates formatted copies. The original files are saved with a .orig extension.
Command 5:
astyle --style=google --indent=spaces=2 --recursive "*.cpp"
Formats all .cpp files in the current directory and its subdirectories using the Google style guide and 2-space indentation.

Options Used:
  • --style=google: Sets the brace style to "google".
  • --indent=spaces=2: Sets indentation style to use 2 spaces.
  • --recursive "*.cpp": Recursively formats all .cpp files in the current directory and its subdirectories.
Output: AStyle formats each .cpp file according to the Google style guide and specified indentation.

Original Files: AStyle retains the original files and generates formatted copies. The original files are saved with a .orig extension.
Command 6:
astyle --style=kr --indent=tab=8 "source.c"
Formats a specific file (source.c) using the K&R style and 8-space tab indentation.

Options Used:
  • --style=kr: Sets the brace style to "K&R".
  • --indent=tab=8: Sets indentation style to use tabs with an 8-space width.
  • source.c: Specifies the file to format.
Output: AStyle formats source.c according to specified options.

Original File: AStyle preserves the original source.c file and creates a formatted copy. The original file is saved with a .orig extension.
Command 7:
astyle --style=stroustrup --pad-oper --suffix=none "*.java"
Formats all .java files in the current directory using the Stroustrup style and adds padding around operators.

Options Used:
  • --style=stroustrup: Sets the brace style to "Stroustrup".
  • --pad-oper: Adds padding around operators.
  • --suffix=none: No backup files are created.
  • "*.java": Matches all files with the .java extension for formatting.
Output: AStyle formats each .java file according to specified options.

Original Files: AStyle modifies the original files without creating backups.
Command 8:
astyle --style=ansi --indent=force-tab=4 --suffix=.bak "*.h"
Formats all .h files in the current directory using ANSI style and forces 4-space tab indentation, with backups saved with a .bak extension.

Options Used:
  • --style=ansi: Sets the brace style to "ANSI".
  • --indent=force-tab=4: Forces tab indentation with a width of 4 spaces.
  • --suffix=.bak: Saves backup files with a .bak extension.
  • "*.h": Matches all files with the .h extension for formatting.
Output: AStyle formats each .h file according to specified options.

Original Files: AStyle retains the original files and generates formatted copies with a .bak extension.
Command 9:
astyle --style=linux --align-pointer=name "*.cpp"
Formats all .cpp files in the current directory using the Linux style and aligns pointers with the variable name.

Options Used:
  • --style=linux: Sets the brace style to "Linux".
  • --align-pointer=name: Aligns pointers with the variable name.
  • "*.cpp": Matches all files with the .cpp extension for formatting.
Output: AStyle formats each .cpp file according to specified options.

Original Files: AStyle modifies the original files and creates backups with a .orig extension.
Command 10:
astyle --style=mozilla --indent=spaces=2 "*.js"
Formats all .js files in the current directory using the Mozilla style and 2-space indentation.

Options Used:
  • --style=mozilla: Sets the brace style to "Mozilla".
  • --indent=spaces=2: Sets indentation style to use 2 spaces.
  • "*.js": Matches all files with the .js extension for formatting.
Output: AStyle formats each .js file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 11:
astyle --style=gnu --add-brackets "*.cxx"
Formats all .cxx files in the current directory using the GNU style and adds brackets to control statements.

Options Used:
  • --style=gnu: Sets the brace style to "GNU".
  • --add-brackets: Adds brackets to control statements.
  • "*.cxx": Matches all files with the .cxx extension for formatting.
Output: AStyle formats each .cxx file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 12:
astyle --style=whitesmith --suffix=none "*.hpp"
Formats all .hpp files in the current directory using the Whitesmith style and does not create backup files.

Options Used:
  • --style=whitesmith: Sets the brace style to "Whitesmith".
  • --suffix=none: No backup files are created.
  • "*.hpp": Matches all files with the .hpp extension for formatting.
Output: AStyle formats each .hpp file according to specified options.

Original Files: AStyle modifies the original files without creating backups.
Command 13:
astyle --style=pico --delete-empty-lines "*.cs"
Formats all .cs files in the current directory using the Pico style and deletes empty lines.

Options Used:
  • --style=pico: Sets the brace style to "Pico".
  • --delete-empty-lines: Deletes empty lines.
  • "*.cs": Matches all files with the .cs extension for formatting.
Output: AStyle formats each .cs file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 14:
astyle --style=kr --indent-classes "*.cpp"
Formats all .cpp files in the current directory using the K&R style and indents class declarations.

Options Used:
  • --style=kr: Sets the brace style to "K&R".
  • --indent-classes: Indents class declarations.
  • "*.cpp": Matches all files with the .cpp extension for formatting.
Output: AStyle formats each .cpp file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 15:
astyle --style=ratliff --indent-switches "*.c"
Formats all .c files in the current directory using the Ratliff style and indents switch statements.

Options Used:
  • --style=ratliff: Sets the brace style to "Ratliff".
  • --indent-switches: Indents switch statements.
  • "*.c": Matches all files with the .c extension for formatting.
Output: AStyle formats each .c file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 16:
astyle --style=horstmann --indent-preproc-block "*.cpp"
Formats all .cpp files in the current directory using the Horstmann style and indents preprocessor blocks.

Options Used:
  • --style=horstmann: Sets the brace style to "Horstmann".
  • --indent-preproc-block: Indents preprocessor blocks.
  • "*.cpp": Matches all files with the .cpp extension for formatting.
Output: AStyle formats each .cpp file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 17:
astyle --style=java --indent=spaces=4 "*.java"
Formats all .java files in the current directory using the Java style and 4-space indentation.

Options Used:
  • --style=java: Sets the brace style to "java".
  • --indent=spaces=4: Sets indentation style to use 4 spaces.
  • "*.java": Matches all files with the .java extension for formatting.
Output: AStyle formats each .java file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 18:
astyle --style=google --convert-tabs --suffix=.bak "*.cpp"
Formats all .cpp files in the current directory using the Google style guide, converts tabs to spaces, and saves backups with a .bak extension.

Options Used:
  • --style=google: Sets the brace style to "google".
  • --convert-tabs: Converts tabs to spaces.
  • --suffix=.bak: Saves backup files with a .bak extension.
  • "*.cpp": Matches all files with the .cpp extension for formatting.
Output: AStyle formats each .cpp file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .bak extension.
Command 19:
astyle --style=kr --attach-namespaces "*.hpp"
Formats all .hpp files in the current directory using the K&R style and attaches namespaces.

Options Used:
  • --style=kr: Sets the brace style to "K&R".
  • --attach-namespaces: Attaches namespaces.
  • "*.hpp": Matches all files with the .hpp extension for formatting.
Output: AStyle formats each .hpp file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.
Command 20:
astyle --style=otbs --align-pointer=name "*.c"
Formats all .c files in the current directory using the One True Brace Style (OTBS) and aligns pointers with variable names.

Options Used:
  • --style=otbs: Sets the brace style to "OTBS".
  • --align-pointer=name: Aligns pointers with variable names.
  • "*.c": Matches all files with the .c extension for formatting.
Output: AStyle formats each .c file according to specified options.

Original Files: AStyle retains the original files and creates backups with a .orig extension.

Thank You

Thank you for visiting this website. If you have any questions or would like to get in touch, please feel free to contact me.

Email 9407959924 GitHub     LinkedIn   LinkTree   Portfolio  Devfolio
Visit on GitHub