11# * nginx* config file formatter/beautifier
22
3- * nginx* config file formatter/beautifier written in Python with no additional dependencies.
4- It can be used as library or standalone script.
5- It formats * nginx* configuration files in consistent way, described below:
3+ * nginx* config file formatter/beautifier written in Python with no additional dependencies.
4+ It can be used as a library or a standalone script.
5+ It formats * nginx* configuration files in a consistent way, described below:
66
7- * All lines are indented in uniform manner, with 4 spaces per level. Number of spaces is customizable.
8- * Neighbouring empty lines are collapsed to at most two empty lines.
9- * Curly braces placement follows Java convention.
10- * Whitespaces are collapsed, except in comments and quotation marks.
7+ * All lines are indented uniformly, with 4 spaces per level. The number of spaces is customizable.
8+ * Neighboring empty lines are collapsed to at most two.
9+ * Curly brace placement follows the Java convention.
10+ * Whitespace is collapsed, except in comments and within quotation marks.
11+ * Newline characters are normalized to the operating system default (LF or CRLF), but this can be overridden.
1112
1213
1314## Installation
1415
15- Python 3.4 or later is needed to run this program. The easiest way is to download package from PyPI:
16+ Python 3.4 or later is needed to run this program.
17+ The easiest way is to download the package from PyPI:
1618
1719``` bash
18- pip3 install nginxfmt
20+ pip install nginxfmt
1921```
2022
2123
2224### Manual installation
2325
24- The simplest form of installation would be copying ` nginxfmt.py ` to your scripts' directory. It has no third party dependencies.
26+ The simplest form of installation is copying ` nginxfmt.py ` to your scripts' directory.
27+ It has no third-party dependencies.
2528
2629You can also clone the repository and symlink the executable:
2730
@@ -34,34 +37,36 @@ ln -s ~/nginx-config-formatter/nginxfmt.py ~/bin/nginxfmt.py
3437
3538## Usage as standalone script
3639
37- It can format one or several files. Result is by default saved to the original file, but can be redirected to * stdout* .
38- It can also function in piping mode, with ` --pipe ` switch.
40+ It can format one or several files.
41+ By default, the result is saved to the original file, but it can be redirected to * stdout* .
42+ It can also function in piping mode, using the ` --pipe ` or ` - ` switch.
3943
4044```
41- usage: nginxfmt.py [-h] [-v] [-] [-p | -b] [-i INDENT] [config_files ...]
45+ usage: nginxfmt.py [-h] [-v] [-] [-p | -b] [-i INDENT] [--line-endings {auto,unix,windows,crlf,lf}] [ config_files ...]
4246
4347Formats nginx configuration files in consistent way.
4448
4549positional arguments:
46- config_files configuration files to format
50+ config_filesconfiguration files to format
4751
48- optional arguments :
49- -h, --help show this help message and exit
50- -v, --verbose show formatted file names
51- -, --pipe reads content from standard input, prints result to stdout
52- -p, --print-result prints result to stdout, original file is not changed
53- -b, --backup-original
54- backup original config file as filename.conf~
52+ options :
53+ -h, --helpshow this help message and exit
54+ -v, --verbose show formatted file names
55+ -, --pipe reads content from standard input, prints result to stdout
56+ -p, --print-resultprints result to stdout, original file is not changed
57+ -b, --backup-original
58+ backup original config file as filename.conf~
5559
5660formatting options:
57- -i INDENT, --indent INDENT
58- specify number of spaces for indentation
61+ -i, --indent INDENT specify number of spaces for indentation
62+ --line-endings {auto,unix,windows,crlf,lf}
63+ specify line ending style: 'unix' or 'lf' for \n, 'windows' or 'crlf' for \r\n. When not provided, system-default is used
5964```
6065
6166
6267## Using as library
6368
64- Main logic is within ` Formatter ` class, which can be used in 3rd -party code.
69+ The main logic is within the ` Formatter ` class, which can be used in third -party code.
6570
6671``` python
6772import nginxfmt
@@ -85,23 +90,25 @@ Customizing formatting options:
8590import nginxfmt
8691
8792fo = nginxfmt.FormatterOptions()
88- fo.indentation = 2 # 2 spaces instead of default 4
93+ fo.indentation = 2 # 2 spaces instead of default 4
94+ fo.line_endings = ' \n ' # force Unix line endings
8995
90- # initializing with standard FormatterOptions
96+ # initialize with standard FormatterOptions
9197f = nginxfmt.Formatter(fo)
9298```
9399
94100
95101## Reporting bugs
96102
97- Please create issue under https://github.com/slomkowski/nginx-config-formatter/issues . Be sure to add config snippets to
98- reproduce the issue, preferably:
99-
100- * snippet do be formatted
101- * actual result with the invalid formatting
102- * desired result
103+ Please create an issue at https://github.com/slomkowski/nginx-config-formatter/issues .
104+ Be sure to include config snippets to reproduce the issue, preferably:
103105
106+ * Snippet to be formatted
107+ * Actual result with the invalid formatting
108+ * Desired result
104109
105110## Credits
106111
107- Copyright 2021 Michał Słomkowski. License: Apache 2.0. Previously published under https://github.com/1connect/nginx-config-formatter .
112+ Copyright 2021 Michał Słomkowski.
113+ License: Apache 2.0.
114+ Previously published under https://github.com/1connect/nginx-config-formatter .
0 commit comments