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

Nested Commands not showing help correctly / nested meta-apps not running #290

Closed
AngellusMortis opened this issue Jan 8, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@AngellusMortis
Copy link

AngellusMortis commented Jan 8, 2025

Definitely a bug or maybe I am just doing things wrong.

I have a nested CLI app structure:

app ->
    app_1 ->
        command_1
        command_2
    app_2 ->
        command_1
        command_2
        command_3

I also have meta-apps for both the parent app and child apps. So top level app is stuff like logging format, logging level, etc. Then the child apps have more specific global options for all of the grouped child commands. The issue is the help does not display right for all child commands or the meta-apps are not executed.

Attempt 1

This leads to the only the top-level meta-app being called (meta_1 is never called):

from cyclopts import App

app_1 = App()

@app_1.meta.default
def meta_1() -> None:
    print("child meta")

app = App()
app.command(app_1)  # <-- difference here

@app.meta.default
def meta() -> None:
    print("parent meta")

if __name__ == "__main__":
    app.meta()

Attempt 2

meta_1 is called, but only the first two levels of --help to work (parent app works, child apps work, but child app commands do not work, it returns the help of the child app instead):

from cyclopts import App

app_1 = App()

@app_1.meta.default
def meta_1() -> None:
    print("child meta")

@app_1.command
def test() -> None:
     pass

app = App()
app.command(app_1.meta)  # <-- difference here

@app.meta.default
def meta() -> None:
    print("parent meta")

if __name__ == "__main__":
    app.meta()

i.e. app --help works, app app_1 --help works, but app app_1 test --help displays the help for app_1.

@BrianPugh
Copy link
Owner

I never really intended meta apps to be nested this way, but I think it could work. A meta app is very similar to an independently declared App, it just gets special treatment relative to it's parent for the --help page. I think your Attempt 2 is closest to working. It's not exactly working as expected on my end; i'll try and open up a PR soon and we can continue discussion there.

@AngellusMortis
Copy link
Author

AngellusMortis commented Jan 9, 2025

I am basically just using meta-apps for app wide arguments. Like I mentioned, the top-level app is for stuff like logging level, output format, etc. Things that are useful for all commands. Then since the current project I am working on is basically a manager for a game server, it is still like hostname/IP, port, RCON port, RCON password, etc. Which that is all data that is shared between the commands in child app, but not the parent app.

@BrianPugh BrianPugh added the bug Something isn't working label Jan 10, 2025
@BrianPugh
Copy link
Owner

#291 is in the newly released v3.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants