configuration: improved error message when config file is missing
This commit is contained in:
@@ -150,6 +150,8 @@ class Config:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls: Type[ConfigInst], path: str) -> ConfigInst:
|
def from_file(cls: Type[ConfigInst], path: str) -> ConfigInst:
|
||||||
|
if not Path(path).exists():
|
||||||
|
raise ConfigError(f"Configuration file '{path}' not found. Use 'cmm config --create' to create one.")
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
source = yaml.load(f, Loader=yaml.FullLoader)
|
source = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
return cls.from_dict(source)
|
return cls.from_dict(source)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import argcomplete
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from .configuration import Config, default_config_file
|
from .configuration import Config, default_config_file, ConfigError
|
||||||
from .message import Message
|
from .message import Message
|
||||||
from .commands.question import question_cmd
|
from .commands.question import question_cmd
|
||||||
from .commands.tags import tags_cmd
|
from .commands.tags import tags_cmd
|
||||||
@@ -220,7 +220,11 @@ def main() -> int:
|
|||||||
if command.func == config_cmd:
|
if command.func == config_cmd:
|
||||||
command.func(command)
|
command.func(command)
|
||||||
else:
|
else:
|
||||||
config = Config.from_file(args.config)
|
try:
|
||||||
|
config = Config.from_file(args.config)
|
||||||
|
except ConfigError as err:
|
||||||
|
print(f"{err}")
|
||||||
|
return 1
|
||||||
create_directories(config)
|
create_directories(config)
|
||||||
command.func(command, config)
|
command.func(command, config)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user