Skip to content

Commit d6f7c86

Browse files
committed
addons/README.md: restructured, rewritten (WIP, RFC)
1 parent 7a0d846 commit d6f7c86

1 file changed

Lines changed: 54 additions & 12 deletions

File tree

addons/README.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,89 @@ Addons are scripts designed to analyze Cppcheck dump files, ensuring compatibili
4444

4545
## Usage
4646

47-
### Command line interface
47+
Addons can be used in three ways:
48+
- Using the `--addon` argument to cppcheck
49+
- Standalone, working on cppcheck dump files
50+
- In the GUI `cppcheck-gui`
51+
52+
### Using the --addon argument to cppcheck
53+
54+
There are several ways to specify an addon on the commandline of cppcheck:
55+
- `--addon=misc` to make cppcheck look for `misc.py` as in next bullet
56+
- `--addon=misc.py` to make cppcheck look for `misc.py` in the current directory and the addon directory
57+
- `--addon=rela/file.py` to load `file.py` from a relative path `./rela/`
58+
- `--addon=/abs/file.py` to load `file.py` from an absolute path `/abs/`
59+
- `--addon=misc.json` to load `misc.json` in the current directory, and [parse as JSON](#-JSON-specification)
60+
- `--addon=rela/misc.json` to load `misc.json` from a relative path `./rela/misc.json`, and [parse as JSON](#-JSON-specification)
61+
- `--addon=/abs/misc.json` to load `misc.json` from an absolute path `/abs/misc.json`, and [parse as JSON](#-JSON-specification)
62+
- `--addon={"script":"misc.py"}` to [parse the JSON](#-JSON-specification) given as the argument
63+
64+
The addon directory is `addons/` below the directory where `cppcheck` resides, i.e.
4865

4966
```bash
50-
cppcheck --addon=misc src/test.c
67+
ADDONS=$(dirname $(which cppcheck))/addons/
68+
echo $ADDONS
69+
```
70+
71+
#### JSON specification
72+
73+
In case JSON is used to specify the addon, the JSON should be structured as follows:
74+
75+
```json
76+
{
77+
"script":"namingng.py",
78+
"args":[
79+
"--configfile=namingng.config.json"
80+
]
81+
}
5182
```
5283

53-
It is also possible to call scripts as follows:
84+
### Standalone
85+
86+
To run an addon in standalone mode, first create a dump file, then give it as an argument to one or more addon scripts:
87+
5488
```bash
55-
cppcheck --dump --quiet src/test.c
56-
python misc.py src/test.c.dump
57-
python misra.py --rule-texts=~/misra_rules.txt src/test.c.dump
89+
cppcheck --dump test.c
90+
ADDONS=$(dirname $(which cppcheck))/addons/
91+
$ADDONS/namingng.py test.c.dump
92+
$ADDONS/misc.py test.c.dump
93+
$ADDONS/misra.py --rule-texts=~/misra_rules.txt test.c.dump
5894
```
5995

60-
This allows you to add additional parameters when calling the script (for example, `--rule-texts` for `misra.py`). The full list of available parameters can be found by calling any script with the `--help` flag.
96+
This allows you to add additional parameters when calling the script (for example, `--rule-texts` for `misra.py`). Note that [using JSON](#-JSON-specification) this is also possible with addons specified on the cppcheck commandline, by adding arguments to the addon to the `args` list. The full list of available parameters can be found by calling any script with the `--help` flag.
6197

6298
### GUI
6399

64100
When using the graphical interface `cppcheck-gui`, the selection and configuration of addons is carried out on the tab `Addons and tools` in the project settings (`Edit Project File`):
65101

66102
![Screenshot](https://raw.githubusercontent.com/danmar/cppcheck/main/addons/doc/img/cppcheck-gui-addons.png)
67103

68-
### Using namingng.py
69104

70-
The `namingng.py` addon can be invoked using:
105+
## Configuring addons
106+
107+
Addons can have configuration options, which are described below.
108+
109+
### Configuring namingng.py
110+
111+
The `namingng.py` addon can be invoked using the methods described above, e.g. utilizing the example `namingng.json` file, referencing the `namingng.config.json` config file:
71112

72113
```bash
73114
ADDONS=$(dirname $(which cppcheck))/addons/
74-
cp $ADDONS/namingng*.json .
115+
cp $ADDONS/namingng.json . # copy JSON addon file
116+
cp $ADDONS/namingng.config.json . # copy JSON addon config file
75117
cppcheck --addon=namingng.json --enable=all test.c
76118
```
77119

78120
Or in standalone mode, using:
79121

80122
```bash
81123
ADDONS=$(dirname $(which cppcheck))/addons/
82-
cp $ADDONS/namingng*.json .
124+
cp $ADDONS/namingng.config.json . # copy JSON addon config file
83125
cppcheck --dump test.c
84126
$ADDONS/namingng.py test.c.dump
85127
```
86128

87-
These commands utilize the example namingng.json file, referencing the namingng.config.json config file. Customize the config file to meet your project's specific requirements.
129+
Both commands utilize the example `namingng.config.json` config file. Customize the config file to meet your project's specific requirements.
88130

89131
The config file, structured as a JSON object, allows you to set rules for:
90132
- files and directories (`RE_FILE`)

0 commit comments

Comments
 (0)