configuration: improved error message when config file is missing
This commit is contained in:
parent
15e8f8fd6b
commit
1932f8f6e9
@ -150,6 +150,8 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
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:
|
||||
source = yaml.load(f, Loader=yaml.FullLoader)
|
||||
return cls.from_dict(source)
|
||||
|
||||
@ -8,7 +8,7 @@ import argcomplete
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from .configuration import Config, default_config_file
|
||||
from .configuration import Config, default_config_file, ConfigError
|
||||
from .message import Message
|
||||
from .commands.question import question_cmd
|
||||
from .commands.tags import tags_cmd
|
||||
@ -220,7 +220,11 @@ def main() -> int:
|
||||
if command.func == config_cmd:
|
||||
command.func(command)
|
||||
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)
|
||||
command.func(command, config)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user