Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed Feb 18, 2024
1 parent ed7774c commit daaa8db
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions instructor/cli/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class HubClient:
def __init__(
self, base_url: str = "https://instructor-hub-proxy.jason-a3f.workers.dev"
):
self.base_url = base_url
self.base_url = "http://localhost:8787"

def get_cookbooks(self, branch):
"""Get collection index of cookbooks."""
url = f"{self.base_url}/api/{branch}/items"
url = f"{self.base_url}/api/{branch}/items/"
response = httpx.get(url)
if response.status_code == 200:
return [HubPage(**page) for page in response.json()]
Expand All @@ -53,7 +53,7 @@ def get_cookbooks(self, branch):

def get_content_markdown(self, branch, slug):
"""Get markdown content."""
url = f"{self.base_url}/api/{branch}/items/{slug}/md"
url = f"{self.base_url}/api/{branch}/items/{slug}/md/"
response = httpx.get(url)
if response.status_code == 200:
return response.text
Expand All @@ -62,7 +62,7 @@ def get_content_markdown(self, branch, slug):

def get_content_python(self, branch, slug):
"""Get Python code blocks from content."""
url = f"{self.base_url}/api/{branch}/items/{slug}/py"
url = f"{self.base_url}/api/{branch}/items/{slug}/py/"
response = httpx.get(url)
if response.status_code == 200:
return response.text
Expand Down Expand Up @@ -118,6 +118,7 @@ def pull(
id: Optional[int] = typer.Option(None, "--id", "-i", help="The cookbook id"),
slug: Optional[str] = typer.Option(None, "--slug", "-s", help="The cookbook slug"),
py: bool = typer.Option(False, "--py", help="Output to a Python file"),
file: Optional[str] = typer.Option(None, "--output", help="Output to a file"),
branch: str = typer.Option(
"hub", help="Specific branch to fetch the cookbooks from."
),
Expand All @@ -143,8 +144,15 @@ def pull(
else Markdown(client.get_content_markdown(branch, cookbook.slug))
)

if file:
with open(file, "w") as f:
f.write(output)
return

if page:
with console.pager(styles=True):
console.print(output)
elif py:
print(output)
else:
console.print(output)

0 comments on commit daaa8db

Please sign in to comment.