Skip to content

Commit 6d891e6

Browse files
committed
Update README and fix warnings. Bump version to 1.3.0. #31
1 parent 026e288 commit 6d891e6

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

README.md

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
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

2629
You 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
4347
Formats nginx configuration files in consistent way.
4448
4549
positional 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
5660
formatting 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
6772
import nginxfmt
@@ -85,23 +90,25 @@ Customizing formatting options:
8590
import nginxfmt
8691

8792
fo = 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
9197
f = 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.

nginxfmt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _load_file_content(self,
111111

112112
if chosen_encoding is None:
113113
raise Exception('none of encodings %s are valid for file %s. Errors: %s'
114-
% (encodings, file_path, [e.message for e in encoding_failures]))
114+
% (encodings, file_path, [str(e) for e in encoding_failures]))
115115

116116
self.logger.info("Loaded file '%s' (detected encoding %s).", file_path, chosen_encoding)
117117

@@ -329,7 +329,9 @@ def _redirect_stdout_to_stderr():
329329

330330
def _aname(action) -> str:
331331
"""Converts argument name to string to be consistent with argparse."""
332-
return argparse._get_action_name(action)
332+
if action.option_strings:
333+
return '/'.join(action.option_strings)
334+
return action.dest
333335

334336

335337
def _standalone_run(program_arguments):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nginxfmt"
3-
version = "1.2.3"
3+
version = "1.3.0"
44
description = "nginx config file formatter/beautifier with no additional dependencies."
55
authors = ["Michał Słomkowski <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)