Skip to content

Commit 7bb374c

Browse files
committed
support comma-separated string tags in config
1 parent 53e5506 commit 7bb374c

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## WIP
4+
5+
- Tag support (#199) to run subsets of rules in your config.
6+
37
## v2.1.2 (2022-02-13)
48

59
- Hotfix for `filecontent` filter.

docs/configuration.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,34 @@ Optionally you can specify the working directory like this:
4848
organize sim [FILE] --working-dir=~/Documents
4949
```
5050

51+
## Running specific rules of your config
52+
53+
You can tag your rules like this:
54+
55+
```yml
56+
rules:
57+
- name: My first rule
58+
actions:
59+
- echo: "Hello world"
60+
tags:
61+
- debug
62+
- fast
63+
```
64+
65+
Then use the command line options `--tags` and `--skip-tags` so select the rules you
66+
want to run. The options take a comma-separated list of tags:
67+
68+
```
69+
organize sim --tags=debug,foo --skip-tags=slow
70+
```
71+
72+
Special tags:
73+
74+
- Rules tagged with the special tag `always` will always run
75+
(except if `--skip-tags=always` is specified)
76+
- Rules tagged with the special tag `never` will never run
77+
(except if ' `--tags=never` is specified)
78+
5179
## Environment variables
5280

5381
- `ORGANIZE_CONFIG` - The path to the default config file.

docs/rules.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rules:
3434
filter_mode: ...
3535
filters: ...
3636
actions: ...
37+
tags: ...
3738

3839
# Another rule
3940
- name: ...
@@ -51,6 +52,7 @@ The rule options in detail:
5152
- **filter_mode** (`str`): `"all"`, `"any"` or `"none"` of the filters must apply _(Default: `"all"`)_
5253
- **filters** (`list`): A list of [filters](filters.md) _(Default: `[]`)_
5354
- **actions** (`list`): A list of [actions](actions.md)
55+
- **tags** (`list`): A list of [tags](configuration.md#running-specific-rules-of-your-config)
5456

5557
## Targeting directories
5658

organize/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TagType(click.ParamType):
6464
def convert(self, value, param, ctx):
6565
if not value:
6666
return tuple()
67-
return tuple(value.split(","))
67+
return tuple(tag.strip() for tag in value.split(","))
6868

6969

7070
CLI_CONFIG = click.argument(

organize/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ def run_rules(rules: dict, tags, skip_tags, simulate: bool = True):
268268

269269
console.spinner(simulate=simulate)
270270
for rule_nr, rule in enumerate(rules["rules"], start=1):
271+
rule_tags = rule.get("tags")
272+
if isinstance(rule_tags, str):
273+
rule_tags = [tag.strip() for tag in rule_tags.split(",")]
271274
should_run = should_execute(
272-
rule_tags=rule.get("tags", []),
275+
rule_tags=rule_tags,
273276
tags=tags,
274277
skip_tags=skip_tags,
275278
)

0 commit comments

Comments
 (0)