Skip to content

Commit 060c231

Browse files
committed
Add sync off command
1 parent 4c33c86 commit 060c231

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

app/commands/progress/sync/off.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1+
import json
2+
import sys
3+
14
import click
25

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+
313

414
@click.command()
515
@click.pass_context
616
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")

app/commands/progress/sync/on.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import os
33
import shutil
4-
from re import LOCALE
54

65
import click
76

@@ -14,12 +13,8 @@
1413
)
1514
from app.utils.click_utils import error, info, success, warn
1615
from app.utils.gh_cli_utils import (
17-
clone,
1816
clone_with_custom_name,
1917
fork,
20-
get_https_or_ssh,
21-
get_repo_https_url,
22-
get_repo_ssh_url,
2318
get_username,
2419
has_fork,
2520
)

app/utils/click_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ def prompt(message: str, default: Optional[Any] = None) -> Any:
4141

4242

4343
def confirm(message: str, abort: bool = False) -> bool:
44-
return click.confirm(f"\n{message}", abort=abort)
44+
return click.confirm(
45+
f"{click.style(' CONFIRM ', fg='black', bg='bright_cyan', bold=True)} {message}",
46+
abort=abort,
47+
)

0 commit comments

Comments
 (0)