Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console functions to zabbix_cli.app.app #219

Open
pederhan opened this issue Sep 30, 2024 · 0 comments
Open

Add console functions to zabbix_cli.app.app #219

pederhan opened this issue Sep 30, 2024 · 0 comments

Comments

@pederhan
Copy link
Member

When writing the plugin guide, it occurred to me that the current API for printing messages could be improved. Instead of importing these functions:

  • zabbix_cli.output.console.success
  • zabbix_cli.output.console.info
  • zabbix_cli.output.console.warning
  • zabbix_cli.output.console.error

We could define methods on zabbix_cli.app.app.StatefulApp which provides these functions wherever we have access to the app object. Furthermore, this would let us give the user more control over the styling of these functions by letting us automatically pass in some sort of state wherever these are accessed.

So in essence we would go from:

from zabbix_cli.output.console import success
from zabbix_cli.output.console import info
from zabbix_cli.output.console import warning
from zabbix_cli.output.console import error

@app.command(name="my_command")
def my_command() -> None:
    success("Success message")
    info("Info message")
    warning("Warning message")
    error("Error message")

To:

from zabbix_cli.app import app

@app.command(name="my_command")
def my_command() -> None:
    app.success("Success message")
    app.info("Info message")
    app.warning("Warning message")
    app.error("Error message")

Or:

from zabbix_cli.app import app

@app.command(name="my_command")
def my_command() -> None:
    app.console.success("Success message")
    app.console.info("Info message")
    app.console.warning("Warning message")
    app.console.error("Error message")

The abstraction is not clear to me yet. We need to figure out if we want to create a rich.console.Console subclass that provides these methods or some sort of thin abstraction class that wraps our existing functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant