Add implicit run on current directory

Fixes: #213
pull/305/head
Sorin Sbarnea 5 years ago
parent 8da98f2122
commit 4c7cd0e2f9

@ -117,12 +117,13 @@ def show_problems(problems, file, args_format, no_warn):
def run(argv=None): def run(argv=None):
parser = argparse.ArgumentParser(prog=APP_NAME, parser = argparse.ArgumentParser(prog=APP_NAME,
description=APP_DESCRIPTION) description=APP_DESCRIPTION)
files_group = parser.add_mutually_exclusive_group(required=True) files_group = parser.add_mutually_exclusive_group()
files_group.add_argument('files', metavar='FILE_OR_DIR', nargs='*', files_group.add_argument('files', metavar='FILE_OR_DIR', nargs='*',
default=(), default=("."),
help='files to check') help='files to check, defaults to "."')
files_group.add_argument('-', action='store_true', dest='stdin', files_group.add_argument(
help='read from standard input') '-', action='store_true', dest='stdin', default=False,
help='read from standard input, ignoring other positional arguments')
config_group = parser.add_mutually_exclusive_group() config_group = parser.add_mutually_exclusive_group()
config_group.add_argument('-c', '--config-file', dest='config_file', config_group.add_argument('-c', '--config-file', dest='config_file',
action='store', action='store',
@ -181,6 +182,7 @@ def run(argv=None):
max_level = 0 max_level = 0
if not args.stdin:
for file in find_files_recursively(args.files, conf): for file in find_files_recursively(args.files, conf):
filepath = file[2:] if file.startswith('./') else file filepath = file[2:] if file.startswith('./') else file
try: try:
@ -192,9 +194,8 @@ def run(argv=None):
prob_level = show_problems(problems, file, args_format=args.format, prob_level = show_problems(problems, file, args_format=args.format,
no_warn=args.no_warnings) no_warn=args.no_warnings)
max_level = max(max_level, prob_level) max_level = max(max_level, prob_level)
else:
# read yaml from stdin # read yaml from stdin
if args.stdin:
try: try:
problems = linter.run(sys.stdin, conf, '') problems = linter.run(sys.stdin, conf, '')
except EnvironmentError as e: except EnvironmentError as e:

Loading…
Cancel
Save