-
Notifications
You must be signed in to change notification settings - Fork 5
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
Idententify an alternative to autocommand #20
Comments
Oh, shoot. Reading through the intro docs, it looks like typer doesn't offer one of the basic ergonomic features of autocommand, the ability to decorate a function and have it be the command. It supports invoking a function as a command, but it still requires the |
Typer docs focus on running example |
See fastapi/typer#928 where I describe what I'd like to see.
Right, but that creates a subcommand. I'd like to decorate and be the command. There's no way to decorate |
I'm now realizing that I can probably build that wrapper.
And |
My friend's project https://github.com/nekitdev/entrypoint does exactly this, I think. |
Nice! But I also want all of the features of typer (function parameter to argument inference, rich help, and completion support). |
I think you are looking for a simple # foo.py
from typer import Typer
app = Typer()
@app.command()
# or @app.callback(invoke_without_command=True)
def main() -> None:
print("called")
__name__ == "__main__" and app() Using both versions of the above snippet in So, trimming down the boilerplate, you could use: from typer import run
def main() -> None:
print("called")
__name__ == "__main__" and run(main) with But yeah, having the |
In jaraco/jaraco.ui@208a1c2, I've added a diff --git a/jaraco/develop/add-github-secret.py b/jaraco/develop/add-github-secret.py
index 32acfcf..9dac8d0 100644
--- a/jaraco/develop/add-github-secret.py
+++ b/jaraco/develop/add-github-secret.py
@@ -1,8 +1,8 @@
-import autocommand
+from jaraco.ui.main import main
from . import github
-@autocommand.autocommand(__name__)
+@main
def run(name, value, project: github.Repo = github.Repo.detect()):
project.add_secret(name, value) But when I did, it failed:
It seems that unlike |
I see there is support for custom types, which uses |
Ugh. And it's ugly - if you want to supply a custom parser class, you have to overspecify whether it's an argument or an option (you lose the inference of Argument or Option based on whether a default has been supplied). |
It does seem that this works: diff --git a/jaraco/develop/add-github-secret.py b/jaraco/develop/add-github-secret.py
index 32acfcf..06b3f7c 100644
--- a/jaraco/develop/add-github-secret.py
+++ b/jaraco/develop/add-github-secret.py
@@ -1,8 +1,17 @@
-import autocommand
+from typing import Annotated
+
+import typer
+from jaraco.ui.main import main
from . import github
-@autocommand.autocommand(__name__)
-def run(name, value, project: github.Repo = github.Repo.detect()):
+@main
+def run(
+ name,
+ value,
+ project: Annotated[
+ github.Repo, typer.Option(parser=github.Repo)
+ ] = github.Repo.detect(),
+):
project.add_secret(name, value) I wonder if it's possible to have |
Another feature that autocommand has was the ability to automatically create long and short switches. Typer will only infer long names, and if you want to specify the short name, you have to supply the long name as well :(. Reported. |
In Lucretiel/autocommand#38, we've learned that autocommand is essentially abandoned, with workflow-breaking bugs unable to be fixed, and the maintainer is unwilling to hand off the projects, so the options are to fork the project or identify an alternative.
I've been pleased with typer in the few places I've tried to use it.
I'd like to explore replacing the use of autocommand with typer. If that goes well, that'll be the way to go. Otherwise, we can fork autocommand as coherent-oss/autocommand or maybe do a rewrite of autocommand.
I'd like to use jaraco.develop as the proving ground, as it has a lot of autocommand usage.
/cc @bswck
The text was updated successfully, but these errors were encountered: