summaryrefslogtreecommitdiffstats
path: root/pre_commit/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/main.py')
-rw-r--r--pre_commit/main.py46
1 files changed, 12 insertions, 34 deletions
diff --git a/pre_commit/main.py b/pre_commit/main.py
index f1e8d03..645e97f 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -1,11 +1,10 @@
+from __future__ import annotations
+
import argparse
import logging
import os
import sys
-from typing import Any
-from typing import Optional
from typing import Sequence
-from typing import Union
import pre_commit.constants as C
from pre_commit import git
@@ -46,34 +45,10 @@ def _add_config_option(parser: argparse.ArgumentParser) -> None:
)
-class AppendReplaceDefault(argparse.Action):
- def __init__(self, *args: Any, **kwargs: Any) -> None:
- super().__init__(*args, **kwargs)
- self.appended = False
-
- def __call__(
- self,
- parser: argparse.ArgumentParser,
- namespace: argparse.Namespace,
- values: Union[str, Sequence[str], None],
- option_string: Optional[str] = None,
- ) -> None:
- if not self.appended:
- setattr(namespace, self.dest, [])
- self.appended = True
- getattr(namespace, self.dest).append(values)
-
-
def _add_hook_type_option(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
- '-t', '--hook-type', choices=(
- 'pre-commit', 'pre-merge-commit', 'pre-push', 'prepare-commit-msg',
- 'commit-msg', 'post-commit', 'post-checkout', 'post-merge',
- 'post-rewrite',
- ),
- action=AppendReplaceDefault,
- default=['pre-commit'],
- dest='hook_types',
+ '-t', '--hook-type',
+ choices=C.HOOK_TYPES, action='append', dest='hook_types',
)
@@ -106,7 +81,7 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
'--from-ref', '--source', '-s',
help=(
- '(for usage with `--from-ref`) -- this option represents the '
+ '(for usage with `--to-ref`) -- this option represents the '
'original ref in a `from_ref...to_ref` diff expression. '
'For `pre-push` hooks, this represents the branch you are pushing '
'to. '
@@ -117,7 +92,7 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
'--to-ref', '--origin', '-o',
help=(
- '(for usage with `--to-ref`) -- this option represents the '
+ '(for usage with `--from-ref`) -- this option represents the '
'destination ref in a `from_ref...to_ref` diff expression. '
'For `pre-push` hooks, this represents the branch being pushed. '
'For `post-checkout` hooks, this represents the branch that is '
@@ -175,7 +150,7 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
args.repo = os.path.relpath(args.repo)
-def main(argv: Optional[Sequence[str]] = None) -> int:
+def main(argv: Sequence[str] | None = None) -> int:
argv = argv if argv is not None else sys.argv[1:]
parser = argparse.ArgumentParser(prog='pre-commit')
@@ -197,7 +172,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
autoupdate_parser.add_argument(
'--bleeding-edge', action='store_true',
help=(
- 'Update to the bleeding edge of `master` instead of the latest '
+ 'Update to the bleeding edge of `HEAD` instead of the latest '
'tagged version (the default behavior).'
),
)
@@ -399,7 +374,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
elif args.command == 'try-repo':
return try_repo(args)
elif args.command == 'uninstall':
- return uninstall(hook_types=args.hook_types)
+ return uninstall(
+ config_file=args.config,
+ hook_types=args.hook_types,
+ )
else:
raise NotImplementedError(
f'Command {args.command} not implemented.',