Coverage for src/lexigram/web/cli/generators/websocket.py: 64%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 04:37 +0800

1"""WebSocket handler generator for the web package.""" 

2 

3from __future__ import annotations 

4 

5from lexigram.codegen import GenerationResult, GeneratorBase 

6 

7 

8class WebSocketHandlerGenerator(GeneratorBase): 

9 """Generate a WebSocket handler scaffold.""" 

10 

11 name = "websocket" 

12 description = "Generate a WebSocket handler for real-time communication" 

13 default_output_dir = "src/websocket" 

14 

15 def __init__(self, output_dir: str = "src/websocket") -> None: 

16 super().__init__(output_dir=output_dir) 

17 

18 def generate( 

19 self, 

20 name: str, 

21 *, 

22 dry_run: bool = False, 

23 force: bool = False, 

24 **options: object, 

25 ) -> GenerationResult: 

26 snake_name = self._to_snake_case(name) 

27 file_path = self.output_dir / f"{snake_name}.py" 

28 content = self.render_template( 

29 "websocket.py.jinja2", 

30 { 

31 "name": self._to_pascal_case(name), 

32 "snake_name": snake_name, 

33 "snake_name_plural": f"{snake_name}s", 

34 }, 

35 ) 

36 return self.write_file(file_path, content, dry_run=dry_run, force=force) 

37 

38 

39__all__ = ["WebSocketHandlerGenerator"]