Skip to content

CLI startup optimization: avoid COM availability probing during parser construction #107

@harumiWeb

Description

@harumiWeb

Before submitting

  • I understand that this project is maintained in spare time and that not all issues may result in changes.

Description

Summary

The CLI currently performs a COM availability check during startup, and on Windows this may instantiate xlwings.App() and effectively launch Excel.
Because this can happen even for lightweight commands such as exstruct --help, it significantly degrades perceived CLI responsiveness.

To improve startup UX, we should stop probing COM availability during parser construction and only evaluate it when a COM-dependent feature is actually used.

Problem

At the moment, COM availability is checked while building the argument parser. This creates several issues:

  • Heavy initialization can run even for --help or argument validation failures
  • On Windows, startup may involve launching and quitting Excel
  • Users experience the CLI as “slow before doing anything”
  • Startup latency becomes more variable and less predictable

In particular, options such as --auto-page-breaks-dir do not need to be conditionally exposed based on a startup-time environment probe.
This is better handled as runtime validation.

Proposal

  • Remove COM availability probing from build_parser()
  • Always expose --auto-page-breaks-dir as a CLI option
  • Validate COM availability only when that option is actually used and a COM-dependent execution path is reached
  • If COM is unavailable, fail at execution time with a clear and explicit error message

Expected benefits

  • Significantly faster startup for commands like exstruct --help
  • Cleaner separation between CLI bootstrap and execution-time capability checks
  • Better first-response UX
  • Fewer side effects during startup

Scope

Potential files:

  • src/exstruct/cli/main.py
  • src/exstruct/cli/availability.py

Acceptance criteria

  • exstruct --help does not trigger COM availability probing
  • Parser construction does not launch Excel
  • --auto-page-breaks-dir is validated at execution time instead
  • In COM-unavailable environments, the CLI returns a clear and actionable error message

Notes

README wording may also need to be updated from:

  • “the option is shown only when supported”

to:

  • “the option is always shown, but validated at runtime based on environment support”

Minimal example (optional)

No response

Additional notes (optional)

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions