Skip to content

Commit

Permalink
Merge pull request #103 from GatorEducator/fix/remove-generate
Browse files Browse the repository at this point in the history
Remove the generate function from the CLI in the --help message
  • Loading branch information
gkapfham authored Sep 10, 2022
2 parents 87f4bfb + 23b23ec commit 9264523
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
59 changes: 33 additions & 26 deletions gatorgrade/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
"""Use Typer to run gatorgrade to run the checks and generate the yml file."""

import glob
import sys
from pathlib import Path
from typing import List

import typer
from rich.console import Console

from gatorgrade.generate.generate import generate_config
from gatorgrade.input.parse_config import parse_config
from gatorgrade.output.output import run_checks

# create an app for the Typer-based CLI
app = typer.Typer(add_completion=False)

# define the emoji that will be prepended to the help message
gatorgrade_emoji = "🐊"

# create a Typer app that
# --> does not support completion
# --> has a specified help message with an emoji
app = typer.Typer(
add_completion=False,
help=f"{gatorgrade_emoji} Run the GatorGrader checks in the specified gatorgrade.yml file.",
)

# create a default console for printing with rich
console = Console()
Expand All @@ -26,9 +33,9 @@
@app.callback(invoke_without_command=True)
def gatorgrade(
ctx: typer.Context,
filename: Path = typer.Option(FILE, "--config", "-c", help="Name of the yml file."),
filename: Path = typer.Option(FILE, "--config", "-c", help="Name of the YML file."),
):
"""Run the GatorGrader checks in the gatorgrade.yml file."""
"""Run the GatorGrader checks in the specified gatorgrade.yml file."""
# if ctx.subcommand is None then this means
# that, by default, gatorgrade should run in checking mode
if ctx.invoked_subcommand is None:
Expand All @@ -55,26 +62,26 @@ def gatorgrade(
sys.exit(FAILURE)


@app.command()
def generate(
root: Path = typer.Argument(
Path("."),
help="Root directory of the assignment",
exists=True,
dir_okay=True,
writable=True,
),
paths: List[Path] = typer.Option(
["*"],
help="Paths to recurse through and generate checks for",
exists=False,
),
):
"""Generate a gatorgrade.yml file."""
targets = []
for path in paths:
targets.extend(glob.iglob(path.as_posix(), recursive=True))
generate_config(targets, root.as_posix())
# @app.command()
# def generate(
# root: Path = typer.Argument(
# Path("."),
# help="Root directory of the assignment",
# exists=True,
# dir_okay=True,
# writable=True,
# ),
# paths: List[Path] = typer.Option(
# ["*"],
# help="Paths to recurse through and generate checks for",
# exists=False,
# ),
# ):
# """Generate a gatorgrade.yml file."""
# targets = []
# for path in paths:
# targets.extend(glob.iglob(path.as_posix(), recursive=True))
# generate_config(targets, root.as_posix())


if __name__ == "__main__":
Expand Down
30 changes: 15 additions & 15 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ def cleanup_files(monkeypatch):
os.remove(file)


def test_generate_creates_valid_yml():
"""Ensure that the generate command creates the .yml file correctly."""
result = runner.invoke(main.app, ["generate"])
print(result.stdout)
assert result.exit_code == 0
# def test_generate_creates_valid_yml():
# """Ensure that the generate command creates the .yml file correctly."""
# result = runner.invoke(main.app, ["generate"])
# print(result.stdout)
# assert result.exit_code == 0


def test_generate_fails_with_existing_yml():
"""Ensure that a second yml file isn't generated without the force command."""
result = runner.invoke(main.app, ["generate"])
print(result.stdout)
assert result.exit_code == 0
# def test_generate_fails_with_existing_yml():
# """Ensure that a second yml file isn't generated without the force command."""
# result = runner.invoke(main.app, ["generate"])
# print(result.stdout)
# assert result.exit_code == 0


def test_generate_force_option_creates_yml():
"""Ensure that the force command works correctly."""
result = runner.invoke(main.app, ["generate"])
print(result.stdout)
assert result.exit_code == 0
# def test_generate_force_option_creates_yml():
# """Ensure that the force command works correctly."""
# result = runner.invoke(main.app, ["generate"])
# print(result.stdout)
# assert result.exit_code == 0


@pytest.mark.parametrize(
Expand Down

0 comments on commit 9264523

Please sign in to comment.