Metadata-Version: 2.1
Name: yamlfixer-opt-nc
Version: 0.3.7
Summary: automates the fixing of problems reported by yamllint
Home-page: https://github.com/opt-nc/yamlfixer
Author: "OPT-NC"
Author-email: "jerome.alet@opt.nc"
License: "GPLv3+"
Project-URL: Bug Tracker, https://github.com/opt-nc/yamlfixer/issues
Project-URL: GitHub Releases, https://github.com/opt-nc/yamlfixer/releases
Project-URL: Files, https://pypi.org/project/yamlfixer-opt-nc/#files
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Environment :: Console
Classifier: Topic :: Utilities
Classifier: Topic :: Text Processing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: yamllint (>=1.26.3)
Requires-Dist: setuptools


[![Docker Image](https://img.shields.io/badge/docker-homepage-blue)](https://hub.docker.com/r/optnc/yamlfixer)
[![Kataocda scenario](https://img.shields.io/badge/katacoda-homepage-blue)](https://www.katacoda.com/opt-labs/courses/devops-tools/yamlfixer)

![PyPI](https://img.shields.io/pypi/v/yamlfixer-opt-nc)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/yamlfixer-opt-nc)
![PyPI - Downloads](https://img.shields.io/pypi/dm/yamlfixer-opt-nc)


# ❔ About

[yamlfixer](https://github.com/opt-nc/yamlfixer) automates the fixing
of problems reported by
[yamllint](https://github.com/adrienverge/yamllint) by parsing its
output.

# 📑 Prerequisites

💡 **You can try the install process online thanks to the dedicated [Katacoda scenario](https://www.katacoda.com/opt-labs/courses/devops-tools/yamlfixer).**

In order for it to work, `yamlfixer` needs that the following
utilities are already installed on your system, in a directory present
in your `$PATH` :

- [x] `Python v3.6` (or higher)
- [x] `yamllint v1.26.3` (or higher)

Then simply install `yamlfixer` from [pypi](https://pypi.org/project/yamlfixer-opt-nc/)

## 🐧Linux install

```shell
python3 -m pip install yamlfixer-opt-nc
```

## 🪟 Windows install

```shell
python -m pip install yamlfixer-opt-nc
```


# 🚀 Usage

This software automatically fixes some errors and warnings reported by
`yamllint`.

```shell
usage: yamlfixer [-h] [-v] [-b] [-d] [-j | -p | -s] [file [file ...]]

Fix formatting problems in YAML documents. If no file is specified,
then reads input from `stdin`.

positional arguments:
  file                the YAML files to fix. Use `-` to read from `stdin`.

optional arguments:
  -h, --help          show this help message and exit
  -v, --version       display this program's version number and exit.
  -b, --backup        make a backup copy of original files as `.orig`
  -d, --debug         output debug information to stderr.
  -j, --jsonsummary   output JSON summary to stderr.
  -p, --plainsummary  output plain text summary to stderr.
  -s, --summary       output colored plain text summary to stderr.
                      If stderr is not a TTY output is identical to
                      --plainsummary.
```

yamlfixer launches `yamllint` on each specified filename, then parses
its output and try to fix the reported problems. The special filename
`-` means `stdin`, and is assumed if there's no other filename
argument.

If input is read from `stdin`, the corrected output will be sent to
`stdout`.

Other files will be overwritten if needed. Original files,
`stdin` excepted, can be preserved as `.orig` if the `--backup`
command line option is used.

Both summaries and diagnostic information are sent to stderr.

This command exits with `-2` if yamllint is not available on your
system. Otherwise it exits with `0` if all input files either are
skipped or successfully pass `yamllint` strict mode, else `-1`.

**IMPORTANT:** Not all problems are fixable by `yamlfixer`. Due to the
fact that `yamllint` doesn't currently report all faulty lines,
`yamlfixer` might even introduce indentation problems under some
circumstances.

⚠️**Use at your own risk, you have been warned...** ⚠️

# 💪 Tips and tips

## ⏩ One liners

Most of use love short and efficient command lines. Here are some ready to use ones : 

### Piping `json`  summary through `jq`

```
yamlfixer --jsonsummary bad.yml 2>&1 | jq
```

So you can get a nicely colored (and vlidated `json` output) : 

```json
  "filestofix": 1,
  "passedstrictmode": 1,
  "modified": 0,
  "skipped": 0,
  "notwriteable": 0,
  "unknown": 0,
  "details": {
    "/home/jerome/yamlfixer/bad.yml": {
      "status": "PASSED",
      "issues": 0,
      "handled": 0
    }
  }
}
```

### Check if `yamlfixer` could fix a `yaml` and get the exit code

See how piping fixing and linting can be interesting... and get exit code
so you can go further in automation :

```
yamlfixer <bad.yml | yamllint --format parsable --strict -
echo $?
```

# 🔖 Related contents

- [Dedicated Post explaining how we are using this project to automate `yaml` linting and fixing](https://dev.to/adriens/let-ci-check-fix-your-yamls-kfa)
- [GH Action relying on this project](https://github.com/marketplace/actions/yaml-fixer)
- [Dedicated Katacoda scenario](https://www.katacoda.com/opt-labs/courses/devops-tools/yamlfixer) so you can see it live

# 📖 Licensing information

```
Copyright (C) 2021-2022 OPT-NC

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
```

# 🧑‍🤝‍🧑 Contact

To contact the [authors](AUTHORS.md) of this software, simply fill an
issue on this project.

OPT-NC, aka _Office des Postes et Télécommunications de Nouvelle-Calédonie_,
has a corporate website on [www.opt.nc](https://www.opt.nc)


