Skip to content

Commit 6451db8

Browse files
committed
Add optional argument for script
1 parent 5757060 commit 6451db8

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

cli.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,46 @@ def submit(ctx: click.Context) -> None:
465465

466466

467467
@cli.command()
468-
@click.argument("script")
468+
@click.argument("script", required=False)
469469
@click.pass_context
470-
def verify(ctx: click.Context, script: str) -> None:
470+
def verify(ctx: click.Context, script: Optional[str]) -> None:
471471
verbose = ctx.obj["VERBOSE"]
472472

473473
check_binary("git", "You need to install Git", verbose)
474474
check_binary("gh", "You need to install the GitHub CLI", verbose)
475475

476+
if script is None:
477+
# Locally verify the changes
478+
# Check that current folder is exercise
479+
gitmastery_exercise_root = find_gitmastery_exercise_root()
480+
if gitmastery_exercise_root is None:
481+
error("You are not inside a Git-Mastery exercise folder.")
482+
483+
assert gitmastery_exercise_root is not None
484+
gitmastery_exercise_root_path, _ = gitmastery_exercise_root
485+
gitmastery_exercise_config = read_gitmastery_exercise_config(
486+
gitmastery_exercise_root_path
487+
)
488+
exercise_name = gitmastery_exercise_config["exercise_name"]
489+
verification = gitmastery_exercise_config.get(
490+
"verification", f"exercise/{exercise_name}"
491+
)
492+
info(
493+
f"Running local verification for {click.style(exercise_name, bold=True, italic=True)} using verification script {click.style(verification, bold=True, italic=True)}"
494+
)
495+
script_url = f"https://raw.githubusercontent.com/git-mastery/local-verifications/refs/heads/main/{verification}.sh"
496+
response = requests.get(script_url)
497+
498+
if response.status_code == 200:
499+
content = response.text
500+
info("The following output is from the local verification script:")
501+
subprocess.run(["bash", "-c", content])
502+
else:
503+
error(
504+
f"Failed to fetch {click.style(verification, bold=True, italic=True)}. Inform the Git-Mastery team."
505+
)
506+
return
507+
476508
script_regex = re.compile("^(hands-on|exercise)/(.*)$")
477509
result = script_regex.search(script)
478510
if result is None:

0 commit comments

Comments
 (0)