Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e22359

Browse files
committed
refactor(cli): extract unknown args validation into a function
1 parent6c8fad1 commit8e22359

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

‎commitizen/cli.py‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,43 @@ def exit_code_from_str_or_skip(s: str) -> ExitCode | None:
612612
]
613613

614614

615+
def_validate_unknown_args_and_parse_as_extra_cli_args(unknown_args:list[str])->str:
616+
"""Validate unknown arguments received from the command line and parse them as extra cli args.
617+
618+
The format of the extra cli args should be like this:
619+
```
620+
cz commit -- -s -n
621+
```
622+
623+
Raises:
624+
InvalidCommandArgumentError: if unknown arguments are found without -- separation
625+
InvalidCommandArgumentError: if unknown arguments are found before -- separator
626+
Warning: if -- separator is found without any following git arguments
627+
"""
628+
629+
# Raise error for extra-args without -- separation
630+
if"--"notinunknown_args:
631+
raiseInvalidCommandArgumentError(
632+
f"Invalid commitizen arguments were found: `{' '.join(unknown_args)}`. "
633+
"Please use -- separator for extra git args"
634+
)
635+
636+
# Raise error for extra-args before --
637+
ifunknown_args[0]!="--":
638+
pos=unknown_args.index("--")
639+
raiseInvalidCommandArgumentError(
640+
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. "
641+
)
642+
643+
# Log warning for -- without any extra args
644+
iflen(unknown_args)==1:
645+
logger.warning(
646+
"\nWARN: Incomplete commit command: received -- separator without any following git arguments\n"
647+
)
648+
649+
return" ".join(unknown_args[1:])
650+
651+
615652
ifTYPE_CHECKING:
616653

617654
classArgs(argparse.Namespace):
@@ -655,25 +692,9 @@ def main() -> None:
655692

656693
arguments=vars(args)
657694
ifunknown_args:
658-
# Raise error for extra-args without -- separation
659-
if"--"notinunknown_args:
660-
raiseInvalidCommandArgumentError(
661-
f"Invalid commitizen arguments were found: `{' '.join(unknown_args)}`. "
662-
"Please use -- separator for extra git args"
663-
)
664-
# Raise error for extra-args before --
665-
elifunknown_args[0]!="--":
666-
pos=unknown_args.index("--")
667-
raiseInvalidCommandArgumentError(
668-
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. "
669-
)
670-
# Log warning for -- without any extra args
671-
eliflen(unknown_args)==1:
672-
logger.warning(
673-
"\nWARN: Incomplete commit command: received -- separator without any following git arguments\n"
674-
)
675-
extra_args=" ".join(unknown_args[1:])
676-
arguments["extra_cli_args"]=extra_args
695+
arguments["extra_cli_args"]= (
696+
_validate_unknown_args_and_parse_as_extra_cli_args(unknown_args)
697+
)
677698

678699
conf=config.read_cfg(args.config)
679700
args=cast("Args",args)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp