Skip to content

Commit

Permalink
Updating documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Mar 24, 2024
1 parent 66201c4 commit 19f339a
Show file tree
Hide file tree
Showing 16 changed files with 3,266 additions and 99 deletions.
83 changes: 26 additions & 57 deletions codelimit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from typing import List, Annotated, Optional

import typer
from rich import print
from click import Context
from rich import print
from typer.core import TyperGroup

from codelimit.commands import github
from codelimit.commands import app
from codelimit.commands.check import check_command
from codelimit.commands.report import report_command
from codelimit.commands.scan import scan_command
from codelimit.commands.upload import upload_command
from codelimit.common.Configuration import Configuration
from codelimit.version import version

Expand All @@ -21,68 +20,38 @@ def list_commands(self, ctx: Context):


cli = typer.Typer(cls=OrderCommands, no_args_is_help=True, add_completion=False)
cli.add_typer(github.app, name="github", help="Code Limit GitHub App commands")
cli.add_typer(app.app, name="app", help="Code Limit GitHub App commands")


@cli.command(help="Check file(s)")
def check(
paths: Annotated[List[Path], typer.Argument(exists=True)],
quiet: Annotated[
bool, typer.Option("--quiet", help="No output when successful")
] = False,
paths: Annotated[List[Path], typer.Argument(exists=True)],
quiet: Annotated[
bool, typer.Option("--quiet", help="No output when successful")
] = False,
):
check_command(paths, quiet)


@cli.command(help="Scan a codebase")
def scan(
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
]
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
]
):
scan_command(path)


@cli.command(help="Show report for codebase")
def report(
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
],
full: Annotated[bool, typer.Option("--full", help="Show full report")] = False,
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
],
full: Annotated[bool, typer.Option("--full", help="Show full report")] = False,
):
report_command(path, full)


@cli.command(help="Upload report to Code Limit GitHub App")
def upload(
repository: Annotated[
str,
typer.Argument(
envvar="GITHUB_REPOSITORY", show_default=False, help="GitHub repository"
),
],
branch: Annotated[
str,
typer.Argument(envvar="GITHUB_REF", show_default=False, help="GitHub branch"),
],
report_file: Path = typer.Option(
None,
"--report",
exists=True,
dir_okay=False,
file_okay=True,
help="JSON report file",
),
token: str = typer.Option(None, "--token", help="GitHub access token"),
url: str = typer.Option(
"https://codelimit.vercel.app/api/upload",
"--url",
help="Upload JSON report to this URL.",
),
):
upload_command(repository, branch, report_file, token, url)


def _version_callback(show: bool):
if show:
print(f"Code Limit version: {version}")
Expand All @@ -91,18 +60,18 @@ def _version_callback(show: bool):

@cli.callback()
def main(
verbose: Annotated[
Optional[bool], typer.Option("--verbose", "-v", help="Verbose output")
] = False,
exclude: Annotated[
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
] = None,
version: Annotated[
Optional[bool],
typer.Option(
"--version", "-V", help="Show version", callback=_version_callback
),
] = None,
verbose: Annotated[
Optional[bool], typer.Option("--verbose", "-v", help="Verbose output")
] = False,
exclude: Annotated[
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
] = None,
version: Annotated[
Optional[bool],
typer.Option(
"--version", "-V", help="Show version", callback=_version_callback
),
] = None,
):
"""CodeLimit: Your refactoring alarm."""
if verbose:
Expand Down
56 changes: 56 additions & 0 deletions codelimit/commands/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from pathlib import Path
from typing import Annotated

import typer
from rich import print

from codelimit.commands.upload import upload_command
from codelimit.github_auth import device_flow_logout, device_flow_login

app = typer.Typer(no_args_is_help=True)


@app.command(help="Login to GitHub App")
def login():
if device_flow_login():
print("[green]Logged in successfully[/green]")
typer.Exit(code=0)
else:
print("[red]Login failed[/red]")
typer.Exit(code=1)


@app.command(help="Logout from GitHub App")
def logout():
device_flow_logout()
print("Logged out")


@app.command(help="Upload report to Code Limit GitHub App")
def upload(
repository: Annotated[
str,
typer.Argument(
envvar="GITHUB_REPOSITORY", show_default=False, help="GitHub repository"
),
],
branch: Annotated[
str,
typer.Argument(envvar="GITHUB_REF", show_default=False, help="GitHub branch"),
],
report_file: Path = typer.Option(
None,
"--report",
exists=True,
dir_okay=False,
file_okay=True,
help="JSON report file",
),
token: str = typer.Option(None, "--token", help="GitHub access token"),
url: str = typer.Option(
"https://codelimit.vercel.app/api/upload",
"--url",
help="Upload JSON report to this URL.",
),
):
upload_command(repository, branch, report_file, token, url)
22 changes: 0 additions & 22 deletions codelimit/commands/github.py

This file was deleted.

Binary file modified docs/assets/easy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/hard-to-maintain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/assets/screenshot.png
Binary file not shown.
Binary file modified docs/assets/unmaintainable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 19f339a

Please sign in to comment.