fixed cli again

This commit is contained in:
Hellow 2023-04-15 12:42:12 +02:00
parent 7599e0db21
commit 4516e40268
2 changed files with 8 additions and 16 deletions

View File

@ -10,6 +10,7 @@ from . import objects, pages
from .utils.config import config, read, write from .utils.config import config, read, write
from .utils.string_processing import fit_to_file_system from .utils.string_processing import fit_to_file_system
from .utils.shared import MUSIC_DIR, MODIFY_GC, NOT_A_GENRE_REGEX, get_random_message from .utils.shared import MUSIC_DIR, MODIFY_GC, NOT_A_GENRE_REGEX, get_random_message
from .utils import exception
if MODIFY_GC: if MODIFY_GC:
""" """
@ -65,16 +66,9 @@ def settings(
def modify_setting(_name: str, _value: str, invalid_ok: bool = True) -> bool: def modify_setting(_name: str, _value: str, invalid_ok: bool = True) -> bool:
try: try:
config.set_name_to_value(_name, _value) config.set_name_to_value(_name, _value)
except ValueError as e: except exception.config.SettingException as e:
if invalid_ok: if invalid_ok:
print() print(e)
print(e.args[0])
return False
else:
raise e
except KeyError as e:
if invalid_ok:
print(f"There is no such setting as: {_name}")
return False return False
else: else:
raise e raise e
@ -86,18 +80,16 @@ def settings(
for i, attribute in enumerate(config): for i, attribute in enumerate(config):
print(f"{i:0>2}: {attribute.name}={attribute.value}") print(f"{i:0>2}: {attribute.name}={attribute.value}")
def modify_setting_by_index(index: int, recursive: bool = True) -> bool: def modify_setting_by_index(index: int) -> bool:
attribute = list(config)[index] attribute = list(config)[index]
print() print()
print(attribute) print(attribute)
input__ = input("New value: ") input__ = input(f"{attribute.name}=")
if not modify_setting(attribute.name, input__.strip()): if not modify_setting(attribute.name, input__.strip()):
if recursive:
return modify_setting_by_index(index) return modify_setting_by_index(index)
else:
return False
return True return True
if name is not None and value is not None: if name is not None and value is not None:

View File

@ -25,4 +25,4 @@ class SettingValueError(SettingException):
self.rule = rule self.rule = rule
def __str__(self): def __str__(self):
return f"{self.setting_name} {self.rule}, not '{self.setting_value}'" return f"{self.setting_name} {self.rule}, not '{self.setting_value}'."