Skip to content

Handler generation command  #10

Open
@hayata-yamamoto

Description

@hayata-yamamoto

Objective

To make handler creation more efficient

What experience is expected

developers execute this command,

ptmpdy generate <handler-name> 

Then, cli creates handler and test file, and insert handler config in serverless.yml

**Repository**

handlers/ 
  <handler-name>
    handler.py

tests/
  handlers/
    <handler-name>
      test_handler.py
# handler.py
from __future__ import annotation

def handler(event: dict, context: dict) -> dict: 
    ...


# test_handler
from handlers.<handler-name> import handler

def test_handler() -> None: 
    ...
# serverless.yml

functions: 
  <handler-name>: 
    handler: <path>.<handler-name>.handler

TBD: Spec

def name_callback(value: str) -> str:
    if condition:  # TODO: validation whether name can be used as python code 
        raise typer.BadParameter("Name should be ...")
    return value

@app.command() 
def generate(
    name: str = Argument(..., callback=name_callback), 
    use_template: bool = Option(default=False), 
    handler_template: Optional[str] = Option(default=None, help='handler code template file'), 
    test_template: Optional[str] = Option(default=None, help='test code template file'),
    skip_test_creation: bool = Option(default=False), 
    skip_handler_creation: bool = Option(default=False), 
    skip_update_yaml: bool = Option(default=False),
) -> None: 
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions