diff --git a/frontools/cli.py b/frontools/cli.py index 474409a..2cb87db 100644 --- a/frontools/cli.py +++ b/frontools/cli.py @@ -39,6 +39,7 @@ def _async_command(function: Any) -> Any: help="Source to use (configured in config file)", ) @option("--no-cache", type=bool, help="Disable caching", count=True) +@option("-u", "--update-index", type=bool, help="Reload cached theme index", count=True) @option( "--include-urls", type=str, @@ -71,6 +72,7 @@ async def main( config_file: Optional[Path], source: str, no_cache: bool, + update_index: bool, include_urls: list[str], exclude_urls: list[str], include_tags: list[str], @@ -79,6 +81,7 @@ async def main( """Utilities for EO frontend development.""" ctx.obj = await Config.load( config_file, + update_index, source, not no_cache, include_urls, diff --git a/frontools/config.py b/frontools/config.py index 4630d54..e6c4ec3 100644 --- a/frontools/config.py +++ b/frontools/config.py @@ -47,7 +47,7 @@ class Config: ) @staticmethod - async def load(config_path: Optional[Path], *args: Any, **kwargs: Any) -> "Config": + async def load(config_path: Optional[Path], update_index: bool, *args: Any, **kwargs: Any) -> "Config": """Load config from the given path""" config = Config(*args, **kwargs) @@ -71,7 +71,7 @@ class Config: config_loader = getattr(config_module, "CONFIG") await config_loader(config) - await config._theme_index.load() + await config._theme_index.load(update_index) return config diff --git a/frontools/theme_index.py b/frontools/theme_index.py index 16539c8..d1cbc2d 100644 --- a/frontools/theme_index.py +++ b/frontools/theme_index.py @@ -40,16 +40,15 @@ class ThemeIndex: def add_urls(self, *urls: UrlEntry) -> None: """Add an url for a theme""" - for url in urls: - self._inputs.urls.append(url) + self._inputs.urls.extend(urls) def add_yaml(self, yaml_path: Path) -> None: """Load a yaml file containing dictionnary of urls to add as themes.""" self._inputs.yaml_files.append(yaml_path) - async def load(self) -> None: + async def load(self, update_cache: bool) -> None: index_cache = xdg_cache_home() / "frontools" / "index-cache.yaml" - if index_cache.is_file(): + if index_cache.is_file() and not update_cache: _Inputs.yaml_files.append(index_cache) else: await self._load_urls_without_theme()