#Error when passing Litestar app as module path on the command line

1 messages · Page 1 of 1 (latest)

spark gale
#

I copied the minimal example from the docs (https://docs.litestar.dev/2/index.html#minimal-example) into a file called example_app.py and tried to run it using litestar run example_app:app. However, I get the following error:

 Usage: litestar run [OPTIONS]

╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ Got unexpected extra argument (example_app:app)                              │
╰──────────────────────────────────────────────────────────────────────────────╯

The CLI help says:

$ litestar run --help

 Usage: litestar run [OPTIONS]

 Run a Litestar app; requires ``uvicorn``.
 The app can be either passed as a module path in the form of <module
 name>.<submodule>:<app instance or factory>, set as an environment variable
 LITESTAR_APP with the same format or automatically discovered from one of
 these canonical paths: app.py, asgi.py, application.py or app/__init__.py.

It does indeed work if I set LITESTAR_APP=example_app:app, but I'd prefer not to have to set the environment variable all the time. Am I missing something obvious or is this a bug in the CLI? Thanks!

tender sunBOT
#
Notes for Error when passing Litestar app as module path on the command line
At your assistance

@spark gale

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

rocky tartan
#

It's litestar <app> run, not litestar run <app>

#

The <app> parameter is part of the litestar command, not the run subcommand. This is because all other subcommands also make use of this parameter

spark gale
#

Oooooh, I see. Thanks!

#

I might submit a PR to point this out in the help text for the run command.

#

!solve