()
| 15 | |
| 16 | # noinspection PyUnusedLocal |
| 17 | def main(): |
| 18 | parser = argparse.ArgumentParser( |
| 19 | prog="scratch", |
| 20 | description="Scratchattach CLI", |
| 21 | epilog=f"Running scratchattach CLI version {cli.VERSION}", |
| 22 | ) |
| 23 | |
| 24 | # Using walrus operator & ifs for artificial indentation |
| 25 | # TODO: there may be a better way to do this |
| 26 | if commands := parser.add_subparsers(dest="command"): |
| 27 | commands.add_parser("profile", help="View your profile") |
| 28 | commands.add_parser("sessions", help="View session list") |
| 29 | if login := commands.add_parser("login", help="Login to Scratch"): |
| 30 | login.add_argument("--sessid", dest="sessid", nargs="?", default=False, const=True, help="Login by session ID") |
| 31 | if group := commands.add_parser("group", help="View current session group"): |
| 32 | if group_commands := group.add_subparsers(dest="group_command"): |
| 33 | group_commands.add_parser("list", help="List all session groups") |
| 34 | group_commands.add_parser("add", help="Add sessions to group") |
| 35 | group_commands.add_parser("remove", help="Remove sessions from a group") |
| 36 | group_commands.add_parser("delete", help="Delete current group") |
| 37 | if group_copy := group_commands.add_parser("copy", help="Copy current group with a new name"): |
| 38 | group_copy.add_argument("group_name", help="New group name") |
| 39 | if group_rename := group_commands.add_parser("rename", help="Rename current group"): |
| 40 | group_rename.add_argument("group_name", help="New group name") |
| 41 | if group_new := group_commands.add_parser("new", help="Create a new group"): |
| 42 | group_new.add_argument("group_name") |
| 43 | if group_switch := group_commands.add_parser("switch", help="Change the current group"): |
| 44 | group_switch.add_argument("group_name") |
| 45 | |
| 46 | parser.add_argument("-U", "--username", dest="username", help="Name of user to look at") |
| 47 | parser.add_argument("-P", "--project", dest="project_id", help="ID of project to look at") |
| 48 | parser.add_argument("-S", "--studio", dest="studio_id", help="ID of studio to look at") |
| 49 | parser.add_argument("-L", "--session_name", dest="session_name", help="Name of (registered) session/login to look at") |
| 50 | |
| 51 | args = parser.parse_args(namespace=cli.ArgSpace()) |
| 52 | handle_args(args, parser) |
| 53 | |
| 54 | |
| 55 | def handle_args(args: cli.ArgSpace, parser: argparse.ArgumentParser): |
no test coverage detected