Skip to content

Commit

Permalink
Set baseline as cli arg
Browse files Browse the repository at this point in the history
  • Loading branch information
blablatdinov committed May 27, 2024
1 parent 0bcf589 commit a9c6c3e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ Run the script:
flake8 script.py | ondivi
```

```bash
ondivi -h
```

```
usage: ondivi [-h] [--baseline BASELINE]
Ondivi (Only diff violations).
Python script filtering coding violations, identified by static analysis,
only for changed lines in a Git repo.
Usage example:
flake8 script.py | ondivi
optional arguments:
-h, --help show this help message and exit
--baseline BASELINE Commit or branch which will contain legacy code. Program filter out violations on baseline (default: "origin/master..HEAD")
```

## How it Works

The script parses the Git diff output to identify the changed lines in each file.
Expand Down
26 changes: 25 additions & 1 deletion ondivi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
only for changed lines in a Git repo.
"""

import argparse
import sys
from contextlib import suppress

Expand Down Expand Up @@ -99,13 +100,36 @@ def controller(diff: Diff, violations: list[str]) -> list[str]:

def main() -> None:
"""Entrypoint."""
parser = argparse.ArgumentParser(
description='\n'.join([
'Ondivi (Only diff violations).\n',
'Python script filtering coding violations, identified by static analysis,',
'only for changed lines in a Git repo.\n',
'Usage example:\n',
'flake8 script.py | ondivi',
]),
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
'--baseline',
dest='baseline',
type=str,
default='origin/master..HEAD',
help=' '.join([
'Commit or branch which will contain legacy code.',
'Program filter out violations on baseline',
'(default: "origin/master..HEAD")',
]),
)
args = parser.parse_args()
violations = sys.stdin.read().strip().splitlines()
sys.stdout.write('\n'.join(
controller(
Repo('.').git.diff('--unified=0', 'origin/master..HEAD'),
Repo('.').git.diff('--unified=0', args.baseline),
violations,
),
))
sys.stdout.write('\n')


if __name__ == '__main__':
Expand Down

0 comments on commit a9c6c3e

Please sign in to comment.