diff --git a/calendar/teachingdates/config/cli.py b/calendar/teachingdates/config/cli.py index 81e5776..5fc7b8d 100644 --- a/calendar/teachingdates/config/cli.py +++ b/calendar/teachingdates/config/cli.py @@ -4,6 +4,30 @@ from teachingdates import PROG +def oxford_comma_list(words): + if isinstance(words, list) or isinstance(words, tuple): + if len(words) == 0: + return "" + elif len(words) == 1: + return words[0] + elif len(words) == 2: + return " and ".join(words) + else: + return ", ".join(words[:-1]) + ", and " + words[-1] + else: + raise TypeError("expected list, got {t}".format(t=str(type(words)))) + + +def switch_message(switches, context, severity="warning", required=False): + switch_string = oxford_comma_list(switches) + return ("{prog}: {severity}: {switches} {verb} {required} for " + "{context}".format(prog=PROG, + severity=severity, + switches=switch_string, + verb="are" if len(switches) > 1 else "is", + required="required" if required else "ignored")) + + def parse_command_line(): """Parse command-line arguments.