Coverage for src / rendercv / cli / create_theme_command / create_theme_command.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-25 13:49 +0000

1import pathlib 

2import textwrap 

3from typing import Annotated 

4 

5import rich.panel 

6import typer 

7from rich import print 

8 

9from rendercv.exception import RenderCVUserError 

10 

11from ..app import app 

12from ..copy_templates import copy_templates 

13from ..error_handler import handle_user_errors 

14from .create_init_file_for_theme import create_init_file_for_theme 

15 

16 

17@app.command( 

18 name="create-theme", 

19 help=( 

20 "Create a custom theme folder with Typst templates to customize. Example:" 

21 " [yellow]rendercv create-theme customtheme[/yellow]. Details: [cyan]rendercv" 

22 " create-theme --help[/cyan]" 

23 ), 

24) 

25@handle_user_errors 

26def cli_command_create_theme( 

27 theme_name: Annotated[ 

28 str, 

29 typer.Argument(help="The name of the new theme"), 

30 ], 

31) -> None: 

32 new_theme_folder = pathlib.Path.cwd() / theme_name 

33 

34 if new_theme_folder.exists(): 

35 message = f'The theme folder "{theme_name}" already exists!' 

36 raise RenderCVUserError(message) 

37 

38 copy_templates("typst", new_theme_folder) 

39 

40 # Create the __init__.py file for the new theme: 

41 create_init_file_for_theme(theme_name, new_theme_folder / "__init__.py") 

42 

43 # Build the panel 

44 message = textwrap.dedent(f""" 

45 [green]✓[/green] Created your custom theme: [purple]./{theme_name}[/purple] 

46 

47 What you can do with this theme: 

48 1. Modify the Typst templates in [purple]./{theme_name}/ 

49 2. Edit [purple]./{theme_name}/__init__.py[/purple] to: 

50 - Add your own design options to use in the YAML input file 

51 - Change the default values of existing options 

52 - Or simply delete it if you only want to customize templates 

53 

54 To use your theme, set in your YAML input file: 

55 [cyan] design: 

56 [cyan] theme: {theme_name} 

57 """).strip("\n") 

58 

59 print( 

60 rich.panel.Panel( 

61 message, 

62 title="Theme created", 

63 title_align="left", 

64 border_style="bright_black", 

65 ) 

66 )