System Gen89 @ 2025-07-25-01:02:05 by jonas@monolith

This commit is contained in:
2025-07-25 01:02:06 +02:00
parent 7857c36e1c
commit 87e526dec7
4 changed files with 39 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ class Config:
cache_file: Path = Path(xdg_cache_home) / Path("spotify-shortcuts.json")
client_id: str | None = None
client_secret: str | None = None
notifications: bool = True
@staticmethod
def from_file(path: Path):
@@ -48,15 +49,26 @@ def load_config(args: List[str] = argv[1:]) -> Config:
default=Config.client_secret,
help="Spotify API Client Secret",
)
parser.add_argument(
"--config-file",
type=str,
help="Path to a json configuration file with keys clientId and clientSecret",
)
parser.add_argument(
"--no-notifications",
action="store_true",
help="Disable desktop notifications",
)
ns = parser.parse_args(args)
cfg = Config()
if (cfg_file := getenv("SPOTIFY_SHORTCUTS_CONFIG", None)) != None:
if (cfg_file := ns.config_file or getenv("SPOTIFY_SHORTCUTS_CONFIG", None)) != None:
cfg = Config.from_file(Path(cfg_file))
return Config(
cache_file=ns.cache_file or cfg.cache_file,
client_id=ns.client_id or cfg.client_id,
client_secret=ns.client_secret or cfg.client_secret,
notifications=not ns.no_notifications or cfg.notifications,
)