Skip to content

Commit 1ec1271

Browse files
committed
ui: some refactoring in main.py
1 parent b9c41e1 commit 1ec1271

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

pyglossary/ui/main.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,29 @@ class MainPrepareResult:
116116
convertOptions: dict[str, Any]
117117

118118

119-
# TODO:
119+
def getConvertOptions(args: argparse.Namespace) -> dict[str, Any]:
120+
convertOptions: dict[str, Any] = {}
121+
for key in convertOptionsKeys:
122+
value = getattr(args, key, None)
123+
if value is not None:
124+
convertOptions[key] = value
125+
126+
infoOverride: dict[str, str] = {}
127+
for key, validate in infoOverrideSpec:
128+
value = getattr(args, key, None)
129+
if value is None:
130+
continue
131+
value = validate(value)
132+
if value is None:
133+
continue
134+
infoOverride[key] = value
135+
if infoOverride:
136+
convertOptions["infoOverride"] = infoOverride
137+
return convertOptions
138+
139+
120140
# PLR0911 Too many return statements (7 > 6)
121-
# PLR0915 Too many statements (56 > 50)
122-
def mainPrepare(argv: list[str]) -> tuple[bool, MainPrepareResult | None]:
141+
def mainPrepare(argv: list[str]) -> tuple[bool, MainPrepareResult | None]: # noqa: PLR0911
123142
global log
124143

125144
uiBase = UIBase()
@@ -207,23 +226,7 @@ def mainPrepare(argv: list[str]) -> tuple[bool, MainPrepareResult | None]:
207226
config.update(configFromArgs(args, log))
208227
logHandler.config = config
209228

210-
convertOptions: dict[str, Any] = {}
211-
for key in convertOptionsKeys:
212-
value = getattr(args, key, None)
213-
if value is not None:
214-
convertOptions[key] = value
215-
216-
infoOverride: dict[str, str] = {}
217-
for key, validate in infoOverrideSpec:
218-
value = getattr(args, key, None)
219-
if value is None:
220-
continue
221-
value = validate(value)
222-
if value is None:
223-
continue
224-
infoOverride[key] = value
225-
if infoOverride:
226-
convertOptions["infoOverride"] = infoOverride
229+
convertOptions = getConvertOptions(args)
227230

228231
if args.inputFilename and readOptions:
229232
readOptions, err = evaluateReadOptions(

0 commit comments

Comments
 (0)