Skip to content

feat(cli,mcp): accept -h and -V/--version - #200

Merged
LukasGold merged 2 commits into
mainfrom
fix/199-version-help-flags
Sep 22, 2026
Merged

LukasGold merged 2 commits into
mainfrom
fix/199-version-help-flags

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Closes #199

Changes

  • osw: -h is an alias of --help on the root and on every subcommand and group. --help stays the first help option name, so click's usage hint still reads "Try '... --help' for help.".
  • osw --version / -V: an eager root option that prints one line and exits 0 before the root callback runs. It needs no configuration, credentials or network, and builds no Context.
  • osw-mcp now parses its arguments with argparse (main(argv=None), reading sys.argv[1:]):
    • -h / --help prints the help and exits 0,
    • -V / --version prints the version line and returns,
    • any other argument, including an abbreviation such as --vers (allow_abbrev=False), is a usage error with exit code 2.
      All three happen before the server is built, so none of them needs credentials. With no argument the server starts as before.
  • New osw.service.version.version_line(prog) builds the line for both commands:
    osw 2.6.2 from C:\...\osw-python\src\osw (Python 3.12.7)
    osw-mcp 2.6.2 from C:\...\osw-python\src\osw (Python 3.12.7)
    
  • Both version paths force stdout to UTF-8 before printing, because the line holds the install path, and a redirected stdout on Windows otherwise uses cp1252 with strict errors.
  • --version and -V are added to _ROOT_OPTIONS, so osw entity --version says the flag belongs before the command. -h/--help are not added, because they are valid after a command.
  • The osw-mcp help text keeps its documentation URL on one line at any terminal width, and points to docs/tools/mcp.md on GitHub.
  • Docs: docs/tools/cli.md and docs/tools/mcp.md describe the new flags.

Rationale

  • -h and -V are the usual short forms. -v is already --verbose in osw. -H is not added: other tools use it for other things (curl -H, grep -H, ls -H).
  • The location is part of the version line because the version comes from package metadata written at install time. In an editable checkout it does not follow later commits: a checkout at v2.4.0-60-gbd849e9 reports 2.4.0. The location shows that the code is a checkout. pip --version prints the same kind of line.
  • The help text links to GitHub, not to the docs site, because https://opensemanticlab.github.io/osw-python/tools/mcp/ returns 404. GitHub Pages uses build_type: workflow and serves an old mkdocs upload instead of the gh-pages branch that mike deploys to, so no current docs page is reachable there, including /dev/ and /latest/.

Behaviour change

osw-mcp used to ignore every argument and start the server. It now rejects an unknown argument with exit code 2. An MCP client configuration that passes a stray argument will fail to start instead of starting and ignoring it.

Tests

  • tests/test_cli.py: -h on the root, a group and a leaf command; --version and -V compared exactly with a line built in the test, with every OSW_* variable removed; --version builds no Context; --version/-V after a command gives the root-option hint; the usage hint names --help; the version callback writes UTF-8 to a cp1252 stdout.
  • tests/test_mcp_server.py: -V, --version, -h, an unknown and an abbreviated argument, each without building the server; main() with no argument reads sys.argv; the help text is ASCII and keeps the URL on one line at 60, 90 and 132 columns. Existing calls to server.main() now pass [], because under pytest sys.argv holds pytest's own arguments.
  • tests/test_osw_entry.py: osw --version through the console script prints only the version line and no import notice.

Local: 704 passed, 90 passed with GITHUB_ACTIONS=true for the CLI, MCP and entry-point tests, and make check passed.

- osw: -h is an alias of --help on every command
- osw and osw-mcp: -V/--version print one line and exit 0
- the line names the version, package location and Python version
- neither flag needs configuration, credentials or network
- osw-mcp rejects an unknown or abbreviated argument with exit 2
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.7.0 (current: v2.6.2).

Changelog preview (truncated)
## v2.7.0 (2026-09-22)

### Features

- **cli,mcp**: Accept -h and -V/--version
  ([`39c603e`](https://github.com/OpenSemanticLab/osw-python/commit/39c603e4b0ea95e49198d1b9d899d9497a61ec5a))

### Testing

- **cli**: Check -h on every command, not three sample paths
  ([`8a65754`](https://github.com/OpenSemanticLab/osw-python/commit/8a65754c04565e8009ac7f0ff29713ac9b937ac0))

Preview via python-semantic-release and conventional commits.

- the commands are generated from the operation registry
- walk the whole click tree and require exit 0 for each
@LukasGold LukasGold self-assigned this Sep 22, 2026
@LukasGold LukasGold added the enhancement New feature or request label Sep 22, 2026
@LukasGold
LukasGold merged commit 41e0162 into main Sep 22, 2026
22 of 23 checks passed
@LukasGold
LukasGold deleted the fix/199-version-help-flags branch September 22, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

osw and osw-mcp do not accept --version, -V or -h

1 participant