Skip to content

Commit

Permalink
Merge pull request #292 from PrefectHQ/dev-cli
Browse files Browse the repository at this point in the history
Add dev CLI
  • Loading branch information
jlowin authored Sep 9, 2024
2 parents 519d559 + 618bc71 commit 09c4fa5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ cython_debug/

# ControlFlow
src/controlflow/_version.py
all_code.md
all_docs.md
1 change: 1 addition & 0 deletions all_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

45 changes: 45 additions & 0 deletions src/controlflow/cli/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pathlib import Path

import typer

dev_app = typer.Typer(no_args_is_help=True)


@dev_app.command()
def generate_ai_files(
output_path: str = typer.Option(
".",
"--output",
"-o",
help="The path where output files will be written. Defaults to current directory.",
),
):
try:
# Get the absolute path of the ControlFlow main repo
repo_root = Path(__file__).resolve().parents[3]
src_path = repo_root / "src"
docs_path = repo_root / "docs"
output_dir = Path(output_path).resolve()

typer.echo(f"Repo root: {repo_root}")
typer.echo(f"src_path: {src_path}")
typer.echo(f"docs_path: {docs_path}")
typer.echo(f"output_dir: {output_dir}")

def generate_file_content(file_paths, output_file):
with open(output_dir / output_file, "w") as f:
for file_path in file_paths:
f.write(f"# ControlFlow Source File: {file_path.absolute()}\n\n")
f.write(file_path.read_text())
f.write("\n\n")

code_files = list(src_path.rglob("*.py")) + list(src_path.rglob("*.jinja"))
doc_files = list(docs_path.rglob("*.mdx")) + list(docs_path.glob("mint.json"))

generate_file_content(code_files, "all_code.md")
generate_file_content(doc_files, "all_docs.md")

typer.echo(f"Generated all_code.md and all_docs.md in {output_dir}")
except Exception as e:
typer.echo(f"An error occurred: {str(e)}", err=True)
raise typer.Exit(code=1)
4 changes: 4 additions & 0 deletions src/controlflow/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from controlflow import __version__
from controlflow.utilities.rich import console

from .dev import dev_app

app = typer.Typer(no_args_is_help=True)

app.add_typer(dev_app, name="dev")


@app.command()
def version(ctx: Context):
Expand Down

0 comments on commit 09c4fa5

Please sign in to comment.