__all__ = ('parse_args',)

import sys
import argparse

from typing import (
	Optional,
)


def parse_args(
	parser: argparse.ArgumentParser,
	args: Optional[list[str]] = None,
) -> tuple[argparse.Namespace, list[str]]:
	if args is None:
		args = sys.argv[1:]

	argv: list[str] = []

	for i, o in enumerate(args):
		if o == '--':
			argv.extend(args[i + 1 :])

			del args[i:]

			break

	return parser.parse_args(args), argv
