Moved all arguments check in the check_args function

This commit is contained in:
Jules Lasne (jlasne - seluj78) 2020-10-14 13:30:22 +02:00
parent e80547bbe4
commit 7defdc8cb2
2 changed files with 39 additions and 24 deletions

View File

@ -7,11 +7,48 @@ from typing import Mapping
def check_args(
path: str, exclude: List[str], below: int, above: int, verbose: int, **kwargs: Any
path: str,
exclude: List[str],
below: int,
above: int,
verbose: int,
only_fuzzy: bool,
offline: bool,
hide_reserved: bool,
counts: bool,
json_format: bool,
exclude_fuzzy: bool,
exclude_reserved: bool,
only_reserved: bool,
show_reservation_dates: bool,
no_cache: bool,
is_interactive: bool,
**kwargs: Any,
) -> Mapping[str, Any]:
# If below is lower than above, raise an error
if below < above:
raise ValueError("'below' must be greater than 'above'.")
print("Potodo: 'below' value must be greater than 'above' value.")
exit(1)
if json_format and is_interactive:
print("Potodo: Json format and interactive modes cannot be activated at the same time.")
exit(1)
if is_interactive:
try:
import termios # noqa
except ImportError:
import platform
print('Potodo: "{}" is not supported for interactive mode'.format(platform.system()))
if exclude_fuzzy and only_fuzzy:
print("Potodo: Cannot pass --exclude-fuzzy and --only-fuzzy at the same time.")
exit(1)
if exclude_reserved and only_reserved:
print("Potodo: Cannot pass --exclude-reserved and --only-reserved at the same time.")
exit(1)
# If no path is specified, use current directory
if not path:

View File

@ -450,28 +450,6 @@ def main() -> None:
args = vars(parser.parse_args())
args.update(check_args(**args))
if args.get("json_format") and args.get("is_interactive"):
print("Json format and interactive modes cannot be activated at the same time.")
exit(1)
if args.get("is_interactive"):
try:
import termios # noqa
except ImportError:
import platform
raise NotImplementedError(
'"{}" is not supported for interactive mode'.format(platform.system())
)
if args.get("exclude_fuzzy") and args.get("only_fuzzy"):
print("Cannot pass --exclude-fuzzy and --only-fuzzy at the same time")
exit(1)
if args.get("exclude_reserved") and args.get("only_reserved"):
print("Cannot pass --exclude-reserved and --only-reserved at the same time")
exit(1)
if args["logging_level"]:
setup_logging(args["logging_level"])