""" Command-line interface for gallery generation. Provides a CLI entry point for gallery generation when using git clone setup. """ import argparse import sys from pathlib import Path from gallery import generate from gallery.config import GalleryConfig def main(): """ Main CLI entry point for gallery generation. Supports: - Loading config from YAML file (default: config.yaml) - Clean gallery directory before generation - Override to process only a specific source directory """ parser = argparse.ArgumentParser( description='Generate scientific gallery from plot collections', formatter_class=argparse.RawDescriptionHelpFormatter, epilog=""" Examples: gallery # Generate from config.yaml gallery --config myconfig.yaml # Use custom config file gallery --clean # Clean and regenerate gallery --source /path/to/plots # Generate only specific source """ ) parser.add_argument( '--config', type=str, default='config.yaml', help='Path to config.yaml file (default: config.yaml)' ) parser.add_argument( '--clean', action='store_true', help='Clean gallery directory before generation' ) parser.add_argument( '--source', type=str, default=None, help='Override to only recompute a specific source directory. ' 'If the directory is not in config, it will be added ' 'temporarily.' ) parser.add_argument( '-v', '--verbose', action='store_true', help='Print verbose output' ) args = parser.parse_args() try: # Load config from file config = GalleryConfig.from_yaml(args.config) # Handle source override if args.source: source_path = Path(args.source).resolve() # Check if source is in config matching_source = None for source in config.sources: if Path(source.path).resolve() == source_path: matching_source = source break # If not in config, create a temporary source entry if matching_source is None: from gallery.config import GallerySource source_name = source_path.name config.sources = [ GallerySource(name=source_name, path=source_path) ] if args.verbose: print( f"Source {args.source} not in config. " f"Adding temporarily as '{source_name}'" ) else: config.sources = [matching_source] # Generate gallery success = generate( config=config, clean_first=args.clean, verbose=args.verbose ) sys.exit(0 if success else 1) except FileNotFoundError as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) except ValueError as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) except Exception as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) if __name__ == '__main__': main()