Skip to content

fix(cli): set --app and --app-dir as eager parameters#4341

Merged
provinzkraut merged 3 commits intolitestar-org:mainfrom
IDrokin117:feature/gh-4331
Sep 29, 2025
Merged

fix(cli): set --app and --app-dir as eager parameters#4341
provinzkraut merged 3 commits intolitestar-org:mainfrom
IDrokin117:feature/gh-4331

Conversation

@IDrokin117
Copy link
Copy Markdown
Contributor

@IDrokin117 IDrokin117 commented Sep 27, 2025

Description

Closes

Fixes #4331

Summary

The problem was in the option value processing. It was expected that the method parse_args would cache the values of app_path and app_dir to use them as default values when LitestarEnv was created. Unfortunately, parser.parse_args(list(args)) doesn't involve option machinery processing (e.g., type validation and casting), so it returns raw values (strings).

This PR solves it by making the app_path and app_dir options eager, so they are always processed before the --help option and are available via ctx.params.

References

Test plan

  • Added test_help_option_with_app_dir test to verify correct CLI behavior when using --app-dir and --help options together

@IDrokin117 IDrokin117 requested review from a team as code owners September 27, 2025 21:06
@github-actions github-actions bot added area/private-api This PR involves changes to the privatized API size: small type/bug pr/external Triage Required 🏥 This requires triage labels Sep 27, 2025
@IDrokin117 IDrokin117 marked this pull request as draft September 27, 2025 21:14
@IDrokin117 IDrokin117 force-pushed the feature/gh-4331 branch 2 times, most recently from 9fcf12b to 09fe04a Compare September 28, 2025 17:28
@IDrokin117 IDrokin117 force-pushed the feature/gh-4331 branch 6 times, most recently from 63ffd89 to a996ae2 Compare September 28, 2025 18:33
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.93%. Comparing base (941a715) to head (ec30aac).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4341      +/-   ##
==========================================
- Coverage   97.93%   97.93%   -0.01%     
==========================================
  Files         321      321              
  Lines       15658    15647      -11     
  Branches     1733     1733              
==========================================
- Hits        15335    15324      -11     
  Misses        185      185              
  Partials      138      138              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@IDrokin117 IDrokin117 changed the title fix(cli): extract preparsed options from ctx.params instead of opts fix(cli): set --app and --app-dir as eager parameters Sep 28, 2025
@github-actions
Copy link
Copy Markdown

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4341

@IDrokin117 IDrokin117 marked this pull request as ready for review September 28, 2025 18:53

@click.group(cls=LitestarExtensionGroup, context_settings={"help_option_names": ["-h", "--help"]})
@click.option("--app", "app_path", help="Module path to a Litestar application")
@click.option("--app", "app_path", help="Module path to a Litestar application", is_eager=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice solution! Didn't even know this flag existed :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL too

@provinzkraut provinzkraut merged commit c4e0337 into litestar-org:main Sep 29, 2025
30 checks passed
@provinzkraut provinzkraut added cherry-pick v2 Automatically create a cherry-pick PR against the `v2` branch when this Pull Request is merged and removed cherry-pick v2 Automatically create a cherry-pick PR against the `v2` branch when this Pull Request is merged labels Sep 29, 2025
provinzkraut pushed a commit that referenced this pull request Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/private-api This PR involves changes to the privatized API cherry-pick v2 Automatically create a cherry-pick PR against the `v2` branch when this Pull Request is merged pr/external size: small Triage Required 🏥 This requires triage type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: combination of --app-dir and --help raises TypeError

3 participants