Skip to content

Commit 2b277e4

Browse files
authored
fix(cli): disable abbreviation to prevent argument parsing collision
* Add failing test * Fix CLI abbreviation --------- Co-authored-by: beroda <[email protected]>
1 parent 5a049ce commit 2b277e4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

tests/data/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from argparse import ArgumentParser
2+
3+
from trame.app import get_server
4+
5+
6+
def main():
7+
parser = ArgumentParser()
8+
parser.add_argument("--f", dest="foo")
9+
parser.parse_known_args()
10+
11+
server = get_server("test_cli")
12+
server.start(timeout=1, open_browser=False)
13+
14+
15+
if __name__ == "__main__":
16+
main()

tests/test_server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22
import os
3+
import subprocess
4+
import sys
35
from pathlib import Path
46

57
import pytest
@@ -125,6 +127,11 @@ def another_method():
125127
server.client_type = "vue3"
126128

127129

130+
def test_cli_args_collision(pytestconfig: pytest.Config):
131+
cli = pytestconfig.rootpath / "tests/data/test_cli.py"
132+
subprocess.run([sys.executable, str(cli), "--f", "foo"], check=True)
133+
134+
128135
def test_cli():
129136
server = get_server("test_cli")
130137
child_server = server.create_child_server(prefix="child_")

trame_server/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ def cli(self):
348348
if self._cli_parser:
349349
return self._cli_parser
350350

351-
self._cli_parser = ArgumentParser(description="Kitware trame")
351+
self._cli_parser = ArgumentParser(
352+
description="Kitware trame",
353+
allow_abbrev=False,
354+
)
352355

353356
# Trame specific args
354357
self._cli_parser.add_argument(

0 commit comments

Comments
 (0)