def command_parser():
class Parser(argparse.ArgumentParser):<EOL><INDENT>def error(self, message):<EOL><INDENT>print("<STR_LIT>".format(message))<EOL>self.print_help()<EOL>self.exit(<NUM_LIT:1>)<EOL><DEDENT>def _check_value(self, action, value):<EOL><INDENT>if action.choices is not None and value not in action.choices:<EOL><INDENT>raise argparse.ArgumentError(<EOL>action, "<STR_LIT>".format(value)<EOL>)<EOL><DEDENT><DEDENT><DEDENT>parser = Parser(formatter_class=argparse.RawTextHelpFormatter)<EOL>for short, name, msg in INFORMATION:<EOL><INDENT>short = "<STR_LIT>" % short<EOL>arg = "<STR_LIT>" % name<EOL>parser.add_argument(short, arg, action="<STR_LIT:store_true>", help=msg)<EOL><DEDENT>metavar = "<STR_LIT>"<EOL>subparsers = parser.add_subparsers(dest="<STR_LIT>", metavar=metavar)<EOL>sps = {}<EOL>data = {"<STR_LIT>": argparse.RawTextHelpFormatter}<EOL>for name, msg, nargs in SUBPARSERS:<EOL><INDENT>data.update({"<STR_LIT>": EPILOGS[name], "<STR_LIT>": msg})<EOL>if name in ["<STR_LIT>"]:<EOL><INDENT>del data["<STR_LIT>"]<EOL><DEDENT>sps[name] = subparsers.add_parser(name, **data)<EOL>sps[name].add_argument(nargs=nargs, dest="<STR_LIT>", help="<STR_LIT>")<EOL><DEDENT>buttons = {<EOL>"<STR_LIT>": <NUM_LIT:1>,<EOL>"<STR_LIT>": <NUM_LIT:2>,<EOL>"<STR_LIT>": <NUM_LIT:3>,<EOL>"<STR_LIT>": <NUM_LIT:4>,<EOL>"<STR_LIT>": <NUM_LIT:5>,<EOL>}<EOL>for name in sorted(buttons):<EOL><INDENT>sps[name] = subparsers.add_parser(name)<EOL>sps[name].add_argument(nargs="<STR_LIT:+>", dest="<STR_LIT>", help="<STR_LIT>")<EOL><DEDENT>sp = sps["<STR_LIT>"]<EOL>for name, msg in CLICK_OPTIONS:<EOL><INDENT>arg = "<STR_LIT>".format(name)<EOL>if name == "<STR_LIT>":<EOL><INDENT>sp.add_argument(arg, metavar="<STR_LIT>", type=int, help=msg, default=<NUM_LIT:1>)<EOL><DEDENT>elif name == "<STR_LIT:index>":<EOL><INDENT>sp.add_argument(arg, metavar="<STR_LIT>", help=msg)<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>sp.add_argument(arg, metavar="<STR_LIT>", help=msg)<EOL><DEDENT>else:<EOL><INDENT>sp.add_argument(arg, metavar="<STR_LIT>", type=int, help=msg)<EOL><DEDENT><DEDENT>sp = sps["<STR_LIT>"]<EOL>for name, msg in DOCSTRING_OPTIONS:<EOL><INDENT>arg = "<STR_LIT>".format(name)<EOL>sp.add_argument(arg, action="<STR_LIT:store_true>", help=msg)<EOL><DEDENT>sp = sps["<STR_LIT>"]<EOL>for name, msg in REFRESH_OPTIONS:<EOL><INDENT>arg = "<STR_LIT>".format(name)<EOL>sp.add_argument(arg, action="<STR_LIT:store_true>", help=msg)<EOL><DEDENT>sp = sps["<STR_LIT:list>"]<EOL>for short, name, msg in LIST_OPTIONS:<EOL><INDENT>name = "<STR_LIT>".format(name)<EOL>if short:<EOL><INDENT>short = "<STR_LIT>".format(short)<EOL>sp.add_argument(short, name, action="<STR_LIT:store_true>", help=msg)<EOL><DEDENT>else:<EOL><INDENT>sp.add_argument(name, action="<STR_LIT:store_true>", help=msg)<EOL><DEDENT><DEDENT>options = parser.parse_args()<EOL>if options.command == "<STR_LIT>":<EOL><INDENT>if options.index:<EOL><INDENT>try:<EOL><INDENT>options.index = int(options.index)<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if options.modifiers:<EOL><INDENT>options.modifiers = options.modifiers.split("<STR_LIT:+>")<EOL><DEDENT>else:<EOL><INDENT>options.modifiers = []<EOL><DEDENT><DEDENT>elif options.command == "<STR_LIT>":<EOL><INDENT>if options.module is None:<EOL><INDENT>options.module = []<EOL><DEDENT>valid = False<EOL>if options.all:  <EOL><INDENT>options.command = "<STR_LIT>"<EOL>options.module = []<EOL>valid = True<EOL><DEDENT>if "<STR_LIT:all>" in options.module:  <EOL><INDENT>options.command = "<STR_LIT>"<EOL>options.module = []<EOL>valid = True<EOL><DEDENT>if not options.module and not valid:<EOL><INDENT>sps["<STR_LIT>"].error("<STR_LIT>")<EOL><DEDENT><DEDENT>elif options.command in ["<STR_LIT:list>", "<STR_LIT>"]:<EOL><INDENT>parse_list_or_docstring(options, sps)<EOL>parser.exit()<EOL><DEDENT>elif options.version:<EOL><INDENT>from platform import python_version<EOL>from py3status.version import version<EOL>print("<STR_LIT>".format(version, python_version()))<EOL>parser.exit()<EOL><DEDENT>elif not options.command:<EOL><INDENT>parser.error("<STR_LIT>")<EOL><DEDENT>alias = options.command in buttons<EOL>new_modules = []<EOL>for index, name in enumerate(options.module):<EOL><INDENT>if name.isdigit():<EOL><INDENT>if alias:<EOL><INDENT>continue<EOL><DEDENT>if not index:  <EOL><INDENT>options.button = int(name)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>new_modules.append(name)<EOL><DEDENT><DEDENT>if alias:<EOL><INDENT>options.button = buttons[options.command]<EOL>options.command = "<STR_LIT>"<EOL><DEDENT>if options.command == "<STR_LIT>" and not new_modules:<EOL><INDENT>sps[options.command].error("<STR_LIT>")<EOL><DEDENT>options.module = new_modules<EOL>return options<EOL>
build and return our command parser