Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jun 19, 2020
2 parents 45785c6 + cc4599d commit ef30b78
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ You can get full report with `--full` command, then all patterns will be include
$ aibolit recommend --folder src/java --full
```

You can exclude folder with `--exclude` command. The last parameter is the folder to exclude,
the rest of them are glob patterns.
```bash
$ aibolit recommend --folder src/java --exclude=**/*Test*.java --exclude=**/*Impl*.java --exclude=/mnt/d/src/java/tests
```

If you need help, run

```bash
Expand Down
34 changes: 31 additions & 3 deletions aibolit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,27 @@ def check():
default=[]
)

parser.add_argument(
'--exclude',
action='append',
nargs='+'
)

args = parser.parse_args(sys.argv[2:])

if args.suppress:
args.suppress = args.suppress.strip().split(',')
if args.threshold:
print('Threshold for model has been set to {}'.format(args.threshold))

files_to_exclude = handle_exclude_command_line(args)

if args.filenames:
files = args.filenames
files = [str(Path(x).absolute()) for x in args.filenames if x not in files_to_exclude]
elif args.folder:
files = []
list_dir(args.folder, files)
all_files = []
list_dir(args.folder, all_files)
files = [str(Path(x).absolute()) for x in all_files if str(x) not in files_to_exclude]

results = list(run_thread(files, args))
exit_code = get_exit_code(results)
Expand All @@ -505,6 +514,25 @@ def check():
return exit_code


def handle_exclude_command_line(args):
files_to_exclude = []
exc_string = 'Usage: --exclude=<glob pattern> ' \
'--exclude=<glob pattern> ... ' \
'--exclude=folder_to_find_exceptions '
if args.exclude:
if len(args.exclude) < 2:
raise Exception(exc_string)
try:
folder_to_exclude = args.exclude[-1][0]
glob_patterns = [x[0] for x in args.exclude[:-1]]
for glob_p in glob_patterns:
files_to_exclude.extend([str(x.absolute()) for x in list(Path(folder_to_exclude).glob(glob_p))])

except Exception:
raise Exception(exc_string)
return files_to_exclude


def format_converter_for_pattern(results, sorted_by=None):
"""Reformat data where data are sorted by patterns importance
(it is already sorted in the input).
Expand Down

0 comments on commit ef30b78

Please sign in to comment.