Created
May 18, 2020 23:03
-
-
Save podhmo/6dcae762e4eb09f310b1a27786517382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from egoist.app import App, SettingsDict, parse_args | |
settings: SettingsDict = {"rootdir": "cmd/", "here": __file__} | |
app = App(settings) | |
app.include("egoist.commands.generate") | |
app.include("commands.now") | |
app.include("egoist.directives.define_cli") | |
@app.define_cli("egoist.generators.clikit:walk") | |
def hello(*, name: str) -> None: | |
"""hello message""" | |
from egoist.generators.clikit import runtime, clikit | |
with runtime.generate(clikit): | |
runtime.printf("hello %s\n", name) | |
if __name__ == "__main__": | |
for argv in parse_args(sep="-"): | |
app.run(argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
import typing as t | |
from functools import partial | |
from egoist.app import App | |
from egoist.types import AnyFunction | |
if t.TYPE_CHECKING: | |
from argparse import ArgumentParser | |
def now(app: App, *, format: str,) -> None: | |
from datetime import datetime | |
now = datetime.now() | |
print(now.strftime(format)) | |
def setup(app: App, sub_parser: ArgumentParser, fn: AnyFunction) -> None: | |
sub_parser.add_argument("--format", default="%Y-%m-%dT%H:%M:%S%z") | |
sub_parser.set_defaults(subcommand=partial(fn, app)) | |
def includeme(app: App) -> None: | |
app.include("egoist.directives.add_subcommand") | |
app.add_subcommand(setup, fn=now) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── commands | |
│ ├── __pycache__ | |
│ │ └── now.cpython-38.pyc | |
│ └── now.py | |
├── definitions.py | |
└── structure.txt | |
2 directories, 4 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment