Skip to content

Commit

Permalink
Replace click with tyro
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Sep 27, 2024
1 parent c1e51f8 commit ada9d52
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 296 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ See also git tags: https://github.com/jedie/manageprojects/tags
[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [**dev**](https://github.com/jedie/manageprojects/compare/v0.19.2...main)
* 2024-09-27 - Replace click with tyro
* 2024-09-25 - Add: test_pre_commit_hooks()
* 2024-09-25 - Move git pre-commit hook from dev-cli.py to update command
* [v0.19.2](https://github.com/jedie/manageprojects/compare/v0.19.1...v0.19.2)
Expand Down
35 changes: 11 additions & 24 deletions manageprojects/cli_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
CLI for usage
"""

import dataclasses
import logging
import sys

import rich_click as click
from cli_base.autodiscover import import_all_files
from cli_base.cli_tools.rich_utils import rich_traceback_install
from cli_base.cli_tools.version_info import print_version
from cli_base.tyro_commands import TyroCommandCli
from rich import print # noqa
from rich.console import Console
from rich.traceback import install as rich_traceback_install

from rich_click import RichGroup

import manageprojects
Expand All @@ -20,25 +22,14 @@
logger = logging.getLogger(__name__)


class ClickGroup(RichGroup): # FIXME: How to set the "info_name" easier?
def make_context(self, info_name, *args, **kwargs):
info_name = './cli.py'
return super().make_context(info_name, *args, **kwargs)


@click.group(
cls=ClickGroup,
epilog=constants.CLI_EPILOG,
)
def cli():
pass
cli = TyroCommandCli()


# Register all click commands, just by import all files in this package:
import_all_files(package=__package__, init_file=__file__)


@cli.command()
@cli.register
def version():
"""Print version and exit"""
# Pseudo command, because the version always printed on every CLI call ;)
Expand All @@ -48,14 +39,10 @@ def version():
def main():
print_version(manageprojects)

console = Console()
rich_traceback_install(
width=console.size.width, # full terminal width
show_locals=True,
suppress=[click],
max_frames=2,
)
rich_traceback_install()

# Execute Click CLI:
cli.name = './cli.py'
cli()
cli.run(
prog='./cli.py',
description=constants.CLI_EPILOG,
)
Loading

0 comments on commit ada9d52

Please sign in to comment.