-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·62 lines (44 loc) · 1.53 KB
/
main.py
File metadata and controls
executable file
·62 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""Main entry point."""
from pathlib import Path
from types import SimpleNamespace
from pydantic import Field
from vrachos.cli import Command
from vrachos.configuration import Configuration
from vrachos.core.io import random_temp_file_path
from vrachos.logger import logger
from vrachos.ui import UI
class AppConfig(Configuration):
"""Custom configuration."""
FILEPATH = Path(random_temp_file_path(suffix="json"))
debug: bool = False
timeout: int = 30
class AppCommand(Command):
"""Demo command."""
NAME = "vrachos"
verbose: bool = Field(False, description="Verbose output", alias="v")
debug: bool = Field(True, description="Debug output", alias="d")
def on_init(self, args: SimpleNamespace) -> None:
"""Initialise the command."""
...
def on_run(self, args: SimpleNamespace) -> None:
"""Run the command."""
print(f"{self.NAME} {self=} {args=}")
if __name__ == "__main__":
UI.init()
AppCommand.run()
print("Test logger")
log_filepath = random_temp_file_path(suffix="log")
logger.add(log_filepath)
logger.debug(f"logger filepath = {log_filepath}")
logger.debug("Hello")
logger.info("Hello")
logger.warning("Hello")
logger.error("Hello")
logger.critical("Hello")
print("Test configuration")
config = AppConfig()
config.load() # Load from file or create with defaults
config.debug = True
config.save() # Atomically write to file
logger.debug(f"AppConfig filepath = {AppConfig.FILEPATH}")