I want Typer to display my commands in the order I have initialized them and it displays those commands in alphabetic order.I have tried different approaches including this one: https://github.com/tiangolo/typer/issues/246In this I get AssertionError. Others like subclassing some Typer and click classes does actually nothing.
Simplified code:
import typerimport osapp = typer.Typer()@app.command()def change_value(file_name, field): print("Here I will change the", file_name, field)@app.command()def close_field(file_name, field): print("I will close field")@app.command()def add_transaction(file_name): print("I will add the transaction")if __name__ == "__main__": app()Please help :)
EDIT:As per @Barmar's request I am adding the code adapted from typer's creator's approach and the error it throws:
CODE:
import typerimport clickfrom click import Contextfrom typing import Iterableapp = typer.Typer()class OrderedCommands(click.Group): def list_commands(self, ctx: Context) -> Iterable[str]: return self.commands.keys()app = typer.Typer(cls=OrderedCommands)@app.command()def change_value(file_name, field): print("Here I will change the", file_name, field)@app.command()def close_field(file_name, field): print("I will close field")@app.command()def add_transaction(file_name): print("I will add the transaction")if __name__ == "__main__": app()ERROR:
│ if __name__ == "__main__": ││❱│ app() ││ (...)(...)AssertionErrorIn the place of (...) there is a list of locals containing the variables and what they store.