typos, standardization, and file association for project extensions
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
Filename: startup_args.py
|
||||
Description: Parses the startup arguments for the application
|
||||
Note: Compliant with pylance strict type checking
|
||||
|
||||
Author: Tyler de Zeeuw
|
||||
License: GPL-3.0
|
||||
"""
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class StartupArgs:
|
||||
finish_update: bool
|
||||
initial_file: str | None
|
||||
|
||||
|
||||
def parse_startup_args(argv: list[str]) -> StartupArgs:
|
||||
"""
|
||||
Parses the command-line flags.
|
||||
|
||||
Recognizes:
|
||||
--finish-update set by the updater when relaunching post-update
|
||||
<path> a project file to open on startup — the first
|
||||
argument that doesn't start with '-', found
|
||||
anywhere in argv rather than assumed to be at
|
||||
a fixed position, so it survives regardless of
|
||||
whether --finish-update precedes it.
|
||||
"""
|
||||
|
||||
finish_update = "--finish-update" in argv[1:]
|
||||
|
||||
initial_file = None
|
||||
for arg in argv[1:]:
|
||||
if not arg.startswith("-"):
|
||||
initial_file = os.path.abspath(arg)
|
||||
break
|
||||
|
||||
return StartupArgs(finish_update=finish_update, initial_file=initial_file)
|
||||
Reference in New Issue
Block a user