mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Add fancy CLI options
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from configparser import ConfigParser, SectionProxy
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@ -68,7 +70,7 @@ class Config:
|
||||
raise ConfigLoadException()
|
||||
|
||||
@staticmethod
|
||||
def load_parser(path: Optional[Path] = None) -> ConfigParser:
|
||||
def load_parser(parser: ConfigParser, path: Optional[Path] = None) -> None:
|
||||
"""
|
||||
May throw a ConfigLoadException.
|
||||
"""
|
||||
@ -76,8 +78,6 @@ class Config:
|
||||
if not path:
|
||||
path = Config._default_path()
|
||||
|
||||
parser = ConfigParser()
|
||||
|
||||
# Using config.read_file instead of config.read because config.read
|
||||
# would just ignore a missing file and carry on.
|
||||
try:
|
||||
@ -90,8 +90,6 @@ class Config:
|
||||
except PermissionError:
|
||||
Config._fail_load(path, "Insufficient permissions")
|
||||
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
def _fail_dump(path: Path, reason: str) -> None:
|
||||
print(f"Failed to dump config file to {path}")
|
||||
@ -123,7 +121,7 @@ class Config:
|
||||
self._parser.write(f)
|
||||
except FileExistsError:
|
||||
print("That file already exists.")
|
||||
if prompt_yes_no("Overwrite it?", default=False):
|
||||
if asyncio.run(prompt_yes_no("Overwrite it?", default=False)):
|
||||
with open(path, "w") as f:
|
||||
self._parser.write(f)
|
||||
else:
|
||||
@ -133,6 +131,9 @@ class Config:
|
||||
except PermissionError:
|
||||
self._fail_dump(path, "Insufficient permissions")
|
||||
|
||||
def dump_to_stdout(self) -> None:
|
||||
self._parser.write(sys.stdout)
|
||||
|
||||
@property
|
||||
def default_section(self) -> SectionProxy:
|
||||
return self._parser[self._parser.default_section]
|
||||
|
Reference in New Issue
Block a user