Skip to content

Commit 59f0f4c

Browse files
committed
Simplify logging of successful and failed files in CLI + add quiet option
1 parent 5e51de0 commit 59f0f4c

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/humanloop/cli/__main__.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from humanloop import Humanloop
1010
from humanloop.sync.sync_client import SyncClient
1111
from datetime import datetime
12+
import time
1213

1314
# Set up logging
1415
logger = logging.getLogger(__name__)
@@ -132,6 +133,12 @@ def cli(): # Does nothing because used as a group for other subcommands (pull, p
132133
is_flag=True,
133134
help="Show detailed information about the operation",
134135
)
136+
@click.option(
137+
"--quiet",
138+
"-q",
139+
is_flag=True,
140+
help="Suppress output of successful files",
141+
)
135142
@handle_sync_errors
136143
@common_options
137144
def pull(
@@ -141,7 +148,8 @@ def pull(
141148
env_file: Optional[str],
142149
base_dir: str,
143150
base_url: Optional[str],
144-
verbose: bool
151+
verbose: bool,
152+
quiet: bool
145153
):
146154
"""Pull prompt and agent files from Humanloop to your local filesystem.
147155
@@ -177,37 +185,24 @@ def pull(
177185
click.echo(click.style(f"Path: {path or '(root)'}", fg=INFO_COLOR))
178186
click.echo(click.style(f"Environment: {environment or '(default)'}", fg=INFO_COLOR))
179187

180-
successful_files = sync_client.pull(path, environment)
188+
start_time = time.time()
189+
successful_files, failed_files = sync_client.pull(path, environment)
190+
duration_ms = int((time.time() - start_time) * 1000)
181191

182-
# Get metadata about the operation
183-
metadata = sync_client.metadata.get_last_operation()
184-
if metadata:
185-
# Determine if the operation was successful based on failed_files
186-
is_successful = not metadata.get('failed_files') and not metadata.get('error')
187-
duration_color = SUCCESS_COLOR if is_successful else ERROR_COLOR
188-
click.echo(click.style(f"Pull completed in {metadata['duration_ms']}ms", fg=duration_color))
189-
190-
if metadata['successful_files']:
191-
click.echo(click.style(f"\nSuccessfully pulled {len(metadata['successful_files'])} files:", fg=SUCCESS_COLOR))
192-
193-
if verbose:
194-
for file in metadata['successful_files']:
195-
click.echo(click.style(f" ✓ {file}", fg=SUCCESS_COLOR))
196-
else:
197-
files_to_display = metadata['successful_files'][:MAX_FILES_TO_DISPLAY]
198-
for file in files_to_display:
199-
click.echo(click.style(f" ✓ {file}", fg=SUCCESS_COLOR))
200-
201-
if len(metadata['successful_files']) > MAX_FILES_TO_DISPLAY:
202-
remaining = len(metadata['successful_files']) - MAX_FILES_TO_DISPLAY
203-
click.echo(click.style(f" ...and {remaining} more", fg=SUCCESS_COLOR))
204-
if metadata['failed_files']:
205-
click.echo(click.style(f"\nFailed to pull {len(metadata['failed_files'])} files:", fg=ERROR_COLOR))
206-
for file in metadata['failed_files']:
207-
click.echo(click.style(f" ✗ {file}", fg=ERROR_COLOR))
208-
if metadata.get('error'):
209-
click.echo(click.style(f"\nError: {metadata['error']}", fg=ERROR_COLOR))
192+
# Determine if the operation was successful based on failed_files
193+
is_successful = not failed_files
194+
duration_color = SUCCESS_COLOR if is_successful else ERROR_COLOR
195+
click.echo(click.style(f"Pull completed in {duration_ms}ms", fg=duration_color))
196+
197+
if successful_files and not quiet:
198+
click.echo(click.style(f"\nSuccessfully pulled {len(successful_files)} files:", fg=SUCCESS_COLOR))
199+
for file in successful_files:
200+
click.echo(click.style(f" ✓ {file}", fg=SUCCESS_COLOR))
210201

202+
if failed_files:
203+
click.echo(click.style(f"\nFailed to pull {len(failed_files)} files:", fg=ERROR_COLOR))
204+
for file in failed_files:
205+
click.echo(click.style(f" ✗ {file}", fg=ERROR_COLOR))
211206

212207
if __name__ == "__main__":
213208
cli()

src/humanloop/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import typing
3-
from typing import Any, List, Optional, Sequence
3+
from typing import Any, List, Optional, Sequence, Tuple
44

55
import httpx
66
from opentelemetry.sdk.resources import Resource
@@ -390,7 +390,7 @@ def agent():
390390
def pull(self,
391391
environment: str | None = None,
392392
path: str | None = None
393-
) -> List[str]:
393+
) -> Tuple[List[str], List[str]]:
394394
"""Pull Prompt and Agent files from Humanloop to local filesystem.
395395
396396
This method will:

0 commit comments

Comments
 (0)