Skip to content

Commit 74097b7

Browse files
committed
cli: Fix allow_interspersed_args not inherited anymore
And make commands.options a protected module.
1 parent bfe9b83 commit 74097b7

File tree

7 files changed

+50
-41
lines changed

7 files changed

+50
-41
lines changed

cli/cloe_launch/commands/options.py renamed to cli/cloe_launch/commands/_options.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
import click
2828

2929

30+
def cli_command(name):
31+
"""Click command with correct settings applied."""
32+
return click.command(name, context_settings={"allow_interspersed_args": False})
33+
34+
3035
def conanfile():
3136
"""Click argument CONANFILE."""
3237
return click.argument(
@@ -36,7 +41,7 @@ def conanfile():
3641

3742
def args():
3843
"""Click argument ARGS."""
39-
return click.argument("args", nargs=-1)
44+
return click.argument("args", nargs=-1, type=click.UNPROCESSED)
4045

4146

4247
def split_args(xargs) -> Tuple[List[str], List[str]]:

cli/cloe_launch/commands/activate.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626

2727
from cloe_launch import Configuration
2828
from cloe_launch.exec import Engine
29-
from . import options
29+
from . import _options
30+
from ._options import cli_command
3031

31-
32-
@click.command("activate")
33-
@options.cache()
34-
@options.conanfile()
35-
@options.args()
32+
@cli_command("activate")
33+
@_options.cache()
34+
@_options.conanfile()
35+
@_options.args()
3636
@click.pass_obj
3737
def cli_activate(
3838
conf: Configuration,
@@ -71,5 +71,5 @@ def cli_activate(
7171
command instead of `activate`.
7272
"""
7373
engine = Engine(conf, conanfile=conanfile)
74-
engine.conan_args = options.extract_conan_args(args)
74+
engine.conan_args = _options.extract_conan_args(args)
7575
engine.activate(use_cache=cache)

cli/cloe_launch/commands/clean.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
from cloe_launch import Configuration
3131
from cloe_launch.exec import Engine
32-
from . import options
32+
from . import _options
33+
from ._options import cli_command
3334

3435

35-
@click.command("clean")
36+
@cli_command("clean")
3637
@click.option("--all", is_flag=True, help="Clean all runtime environments.")
37-
@options.conanfile()
38+
@_options.conanfile()
3839
@click.pass_obj
3940
def cli_clean(
4041
conf: Configuration,

cli/cloe_launch/commands/deploy.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030

3131
from cloe_launch import Configuration
3232
from cloe_launch.exec import Engine
33-
from . import options
33+
from . import _options
34+
from ._options import cli_command
3435

3536

36-
@click.command("deploy")
37+
@cli_command("deploy")
3738
@click.option(
3839
"-D",
3940
"--dest",
@@ -53,8 +54,8 @@
5354
default=True,
5455
help="Set the RPATH of all binaries and libraries.",
5556
)
56-
@options.conanfile()
57-
@options.args()
57+
@_options.conanfile()
58+
@_options.args()
5859
@click.pass_obj
5960
def cli_deploy(
6061
conf: Configuration,
@@ -76,7 +77,7 @@ def cli_deploy(
7677
cloe-launch deploy -D deploy tests/conanfile.py
7778
"""
7879
engine = Engine(conf, conanfile=conanfile)
79-
engine.conan_args = options.extract_conan_args(args)
80+
engine.conan_args = _options.extract_conan_args(args)
8081

8182
try:
8283
engine.deploy(

cli/cloe_launch/commands/exec.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929

3030
from cloe_launch import Configuration
3131
from cloe_launch.exec import Engine
32-
from . import options
32+
from . import _options
33+
from ._options import cli_command
3334

34-
35-
@click.command("exec")
36-
@options.preserve_env()
37-
@options.override_env()
38-
@options.cache()
35+
@cli_command("exec")
36+
@_options.preserve_env()
37+
@_options.override_env()
38+
@_options.cache()
3939
@click.option(
4040
"-d",
4141
"--debug",
4242
is_flag=True,
4343
help="Launch cloe-engine with GDB.",
4444
)
45-
@options.conanfile()
46-
@options.args()
45+
@_options.conanfile()
46+
@_options.args()
4747
@click.pass_obj
4848
def cli_exec(
4949
conf: Configuration,
@@ -69,13 +69,13 @@ def cli_exec(
6969
cloe-launch exec -c tests/conanfile.py -- -l debug run tests/smoketest.json
7070
"""
7171
engine = Engine(conf, conanfile=conanfile)
72-
engine.conan_args = options.extract_conan_args(args)
72+
engine.conan_args = _options.extract_conan_args(args)
7373
engine.preserve_env = preserve_env
7474

7575
# Run cloe-engine and pass on returncode:
7676
# If cloe-engine is killed/aborted, subprocess will return 250.
77-
engine_args = options.extract_target_args(args)
78-
overrides = options.process_overrides(override_env)
77+
engine_args = _options.extract_target_args(args)
78+
overrides = _options.process_overrides(override_env)
7979
result = engine.exec(
8080
engine_args, use_cache=cache, debug=debug, override_env=overrides
8181
)

cli/cloe_launch/commands/prepare.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
from cloe_launch import Configuration
3131
from cloe_launch.exec import Engine
32-
from . import options
32+
from . import _options
33+
from ._options import cli_command
3334

3435

35-
@click.command("prepare")
36-
@options.conanfile()
37-
@options.args()
36+
@cli_command("prepare")
37+
@_options.conanfile()
38+
@_options.args()
3839
@click.pass_obj
3940
def cli_prepare(
4041
conf: Configuration,
@@ -60,7 +61,7 @@ def cli_prepare(
6061
cloe-launch prepare tests/conanfile.py --require-override boost/1.81
6162
"""
6263
engine = Engine(conf, conanfile=conanfile)
63-
engine.conan_args = options.extract_conan_args(args)
64+
engine.conan_args = _options.extract_conan_args(args)
6465

6566
try:
6667
engine.prepare()

cli/cloe_launch/commands/shell.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828

2929
from cloe_launch import Configuration
3030
from cloe_launch.exec import Engine
31-
from . import options
31+
from . import _options
32+
from ._options import cli_command
3233

3334

34-
@click.command("shell")
35-
@options.preserve_env()
36-
@options.override_env()
37-
@options.cache()
38-
@options.conanfile()
39-
@options.args()
35+
@cli_command("shell")
36+
@_options.preserve_env()
37+
@_options.override_env()
38+
@_options.cache()
39+
@_options.conanfile()
40+
@_options.args()
4041
@click.pass_obj
4142
def cli_shell(
4243
conf: Configuration,
@@ -66,7 +67,7 @@ def cli_shell(
6667
"""
6768
engine = Engine(conf, conanfile=conanfile)
6869
engine.preserve_env = preserve_env
69-
engine.conan_args = options.extract_conan_args(args)
70+
engine.conan_args = _options.extract_conan_args(args)
7071

7172
# Replace process with shell.
72-
engine.shell(options.extract_target_args(args), use_cache=cache)
73+
engine.shell(_options.extract_target_args(args), use_cache=cache)

0 commit comments

Comments
 (0)