Beispiel #1
0
import typing as t
import pathlib
from handofcats import as_command, Config
from monogusa.langhelpers import import_module
from monogusa.web.codegen import codegen


@as_command(config=Config(ignore_expose=True))  # type: ignore
def run(
    target_module: str,
    *,
    dry_run: bool = False,
    dst: t.Optional[str] = None,
    ignore_only: bool = False,
) -> None:
    module = import_module(target_module, cwd=True)
    dst = dst or str(pathlib.Path.cwd())
    codegen(module, dst=dst, with_main=True, dry_run=dry_run, ignore_only=ignore_only)
Beispiel #2
0
from handofcats import as_command, Config
import json


@as_command(config=Config(
    cont=lambda x: print(json.dumps(x, indent=2, ensure_ascii=False))))
def people() -> list:
    import faker

    faker.Faker.seed(0)
    fake = faker.Faker("ja_JP")
    return [{
        "no": i,
        "name": fake.name(),
        "address": fake.address()
    } for i in range(5)]
Beispiel #3
0
from handofcats import as_command, Config


@as_command(config=Config(ignore_expose=True, ignore_logging=True))
def run(*, name: str = "", n: int = 0) -> None:
    print(n, name)
Beispiel #4
0
from handofcats import Config, as_subcommand


@as_subcommand
def foo():
    pass


cfg = Config(ignore_logging=True)
if __name__ == "__main__":
    as_subcommand.run(config=cfg)
Beispiel #5
0
import json
from handofcats import as_command, Config


@as_command(config=Config(cont=lambda x: print(json.dumps(x))))
def hello(*, name="world") -> str:
    return f"hello, {name}"