command_group.py 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from functools import wraps
  2. import asyncclick as click
  3. from asyncclick import pass_context
  4. from asyncclick.exceptions import Exit
  5. from sdk import R2RAsyncClient
  6. def deprecated_command(new_name):
  7. def decorator(f):
  8. @wraps(f)
  9. async def wrapped(*args, **kwargs):
  10. click.secho(
  11. f"Warning: This command is deprecated. Please use '{new_name}' instead.",
  12. fg="yellow",
  13. err=True,
  14. )
  15. return await f(*args, **kwargs)
  16. return wrapped
  17. return decorator
  18. @click.group()
  19. @click.option(
  20. "--base-url", default="http://localhost:7272", help="Base URL for the API"
  21. )
  22. @pass_context
  23. async def cli(ctx, base_url):
  24. """R2R CLI for all core operations."""
  25. ctx.obj = R2RAsyncClient(base_url=base_url)
  26. # Override the default exit behavior
  27. def silent_exit(self, code=0):
  28. if code != 0:
  29. raise Exit(code)
  30. ctx.exit = silent_exit.__get__(ctx)