mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 10:31:46 +04:00
Check --config option is a path to a regular file
This commit is contained in:
parent
1bd9bfefeb
commit
183e205288
1 changed files with 12 additions and 0 deletions
|
|
@ -36,6 +36,17 @@ logger = logging.getLogger('pre_commit')
|
||||||
os.environ.pop('__PYVENV_LAUNCHER__', None)
|
os.environ.pop('__PYVENV_LAUNCHER__', None)
|
||||||
|
|
||||||
|
|
||||||
|
def _file_path(path):
|
||||||
|
if os.path.isfile(path):
|
||||||
|
return path
|
||||||
|
elif os.path.exists(path):
|
||||||
|
msg = '{} is not a regular file'.format(path)
|
||||||
|
raise argparse.ArgumentTypeError(msg)
|
||||||
|
else:
|
||||||
|
msg = '{} does not exist'.format(path)
|
||||||
|
raise argparse.ArgumentTypeError(msg)
|
||||||
|
|
||||||
|
|
||||||
def _add_color_option(parser):
|
def _add_color_option(parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--color', default='auto', type=color.use_color,
|
'--color', default='auto', type=color.use_color,
|
||||||
|
|
@ -48,6 +59,7 @@ def _add_config_option(parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--config', default=C.CONFIG_FILE,
|
'-c', '--config', default=C.CONFIG_FILE,
|
||||||
help='Path to alternate config file',
|
help='Path to alternate config file',
|
||||||
|
type=_file_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue