Skip to content

Commit

Permalink
Rewrite handling of environment options
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Oct 20, 2023
1 parent d3b6850 commit 1503fae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 8 additions & 7 deletions vspreview/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
)
parser.add_argument(
'plugins', type=str, nargs='*',
help='Plugins to install/uninstall/update'
help='Plugins to install/uninstall/update or arguments to pass to the script environment.'
)
parser.add_argument(
'--version', '-v', action='version', version='%(prog)s 0.2b'
)
parser.add_argument(
'--preserve-cwd', '-c', action='store_true', help='do not chdir to script parent directory'
)
parser.add_argument(
'--arg', '-a', type=str, action='append', metavar='key=value', help='Argument to pass to the script environment'
)
parser.add_argument('-f', '--frame', type=int, help='Frame to load initially (defaults to 0)')
parser.add_argument(
'--vscode-setup', type=str, choices=['override', 'append', 'ignore'], nargs='?', const='append',
Expand Down Expand Up @@ -98,6 +95,10 @@ def main(_args: Sequence[str] | None = None, no_exit: bool = False) -> int:
logging.error('Script path required.')
return exit_func(1, no_exit)

if script_path_or_command.startswith('--') and args.plugins:
script_path_or_command = args.plugins.pop()
args.plugins = [args.script_path_or_command, *args.plugins]

if (command := script_path_or_command) in plugins_commands:
if not args.plugins:
logging.error('You must provide at least one plugin!')
Expand Down Expand Up @@ -153,10 +154,10 @@ def _parse_arg(kv: str) -> tuple[str, str | int | float]:
except ValueError:
...

return k, v
return k.strip('--'), v

if args.arg:
arguments |= {k: v for k, v in map(_parse_arg, args.arg)}
if args.plugins:
arguments |= {k: v for k, v in map(_parse_arg, args.plugins)}

main.main_window = MainWindow(
Path(os.getcwd()) if args.preserve_cwd else script.path.parent, no_exit, script.reload_enabled
Expand Down
7 changes: 6 additions & 1 deletion vspreview/main/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ def load_script(
self.resolve_plugins.add(resolve_plugin)

self.toolbars.playback.stop()
self.setWindowTitle(f'VSPreview: {self.display_name} {self.external_args}')
self.setWindowTitle(
f'VSPreview: {self.display_name}' + (
f', Arguments({", ".join(f"{k}={v}" for k, v in self.external_args)})'
if self.external_args else ''
)
)

self.statusbar.label.setText('Evaluating')
self.script_path = script_path
Expand Down

0 comments on commit 1503fae

Please sign in to comment.