|
| 1 | +import json |
| 2 | +import sys |
| 3 | + |
1 | 4 | import click |
2 | 5 |
|
| 6 | +from app.commands.check.git import git |
| 7 | +from app.commands.check.github import github |
| 8 | +from app.commands.progress.constants import STUDENT_PROGRESS_FORK_NAME |
| 9 | +from app.utils.click_utils import confirm, error, info |
| 10 | +from app.utils.gh_cli_utils import delete_repo, get_username |
| 11 | +from app.utils.gitmastery_utils import generate_cds_string, require_gitmastery_root |
| 12 | + |
3 | 13 |
|
4 | 14 | @click.command() |
5 | 15 | @click.pass_context |
6 | 16 | def off(ctx: click.Context) -> None: |
7 | | - pass |
| 17 | + """ |
| 18 | + Removes the remote progress sync for Git-Mastery. |
| 19 | + """ |
| 20 | + verbose = ctx.obj["VERBOSE"] |
| 21 | + |
| 22 | + gitmastery_root_path, cds, gitmastery_config = require_gitmastery_root() |
| 23 | + if cds != 0: |
| 24 | + error( |
| 25 | + f"Use {click.style('cd ' + generate_cds_string(cds), bold=True, italic=True)} the root of the Git-Mastery exercises folder to sync your progress." |
| 26 | + ) |
| 27 | + |
| 28 | + if not gitmastery_config.get("progress_remote", False): |
| 29 | + error("You have not enabled sync for Git-Mastery yet.") |
| 30 | + |
| 31 | + result = confirm("Are you sure you want to turn off syncing?") |
| 32 | + if not result: |
| 33 | + info("Cancelling command") |
| 34 | + sys.exit(0) |
| 35 | + |
| 36 | + ctx.invoke(git) |
| 37 | + ctx.invoke(github) |
| 38 | + |
| 39 | + info("Removing fork") |
| 40 | + username = get_username(verbose) |
| 41 | + delete_repo( |
| 42 | + f"{username}/{STUDENT_PROGRESS_FORK_NAME.format(username=username)}", verbose |
| 43 | + ) |
| 44 | + gitmastery_config["progress_remote"] = False |
| 45 | + with open(gitmastery_root_path / ".gitmastery.json", "w") as config_file: |
| 46 | + config_file.write(json.dumps(gitmastery_config)) |
| 47 | + info("Successfully removed your remote sync") |
0 commit comments