Skip to content

Commit ca7cde4

Browse files
committed
[cli] Fix script argv passthrough
1 parent 64fad54 commit ca7cde4

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

ocebuild_cli/__main__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def parse_args(self, ctx, args):
6666

6767
# Store the script path and remaining args in the context
6868
ctx.params['exec_file'] = script_path
69-
ctx.params['args'] = new_args
69+
ctx.obj.pargs = new_args
7070

7171
return [] # No more arguments to process
7272

@@ -78,18 +78,19 @@ def parse_args(self, ctx, args):
7878
@click.option('-e', '--exec', 'exec_file',
7979
type=click.Path(exists=True, dir_okay=False),
8080
help='Run the specified Python file with the CLI environment.')
81-
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
8281
@click.version_option(message='ocebuild-cli %(version)s', version=__version__)
8382
@click.pass_context
84-
def cli(ctx, exec_file=None, args=None):
83+
def cli(ctx, exec_file=None):
8584
"""Main runner for the CLI."""
85+
8686
if exec_file and ctx.invoked_subcommand is None:
8787
try:
8888
# Run python script in a controlled namespace (inherits pyinstaller env)
8989
import runpy, sys
9090

91-
sys.argv = [exec_file] + list(args) if args else [exec_file]
92-
ctx.obj.__dict__['argv'] = list(args) if args else []
91+
args = ctx.obj.pargs
92+
sys.argv = [exec_file] + list(args)
93+
ctx.obj.__dict__['argv'] = args
9394

9495
runpy.run_path(exec_file, run_name="__main__", init_globals=ctx.obj.__dict__)
9596
return

ocebuild_cli/_lib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from functools import wraps as functools_wraps
88

9-
from typing import Optional
9+
from typing import List, Optional
1010

1111
import click
1212

@@ -28,6 +28,7 @@ class CLIEnv:
2828
"""Shared CLI environment."""
2929

3030
tmpdir: Optional[str] = None
31+
pargs: List[str] = []
3132

3233
global VERBOSE, DEBUG
3334
def __init__(self,

scripts/amd.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# ]
1515
# ///
1616

17+
from os import getcwd
18+
from pathlib import Path
19+
1720
import click
1821
from ocebuild.filesystem import extract_archive
1922
from ocebuild.parsers.yaml import write_yaml
@@ -25,6 +28,13 @@
2528

2629

2730
@click.command()
31+
@click.option("-c", "--cwd",
32+
type=click.Path(exists=True,
33+
file_okay=False,
34+
readable=True,
35+
writable=True,
36+
path_type=Path),
37+
help="Use the specified directory as the working directory.")
2838
@click.option('--cpu',
2939
required=True,
3040
type=int,
@@ -36,7 +46,11 @@
3646
default='patch.amd.yml',
3747
show_default=True,
3848
help='Output path for the generated YAML file')
39-
def main(cpu, hyperv, out):
49+
def main(cwd, cpu, hyperv, out):
50+
if not cwd: cwd = getcwd()
51+
cwd = Path(cwd).resolve()
52+
out = cwd / out
53+
4054
with extract_archive(AMD_PATCH_ARCHIVE) as tmp_dir:
4155
plist_file = next(tmp_dir.glob('**/patches.plist'))
4256
amd_patches = write_yaml(read_config(plist_file), schema='annotated')

0 commit comments

Comments
 (0)