Created
February 8, 2020 11:49
-
-
Save podhmo/9437d27a3c35213b2293a50511b5647e 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 handofcats import as_command | |
@as_command | |
def hello(*, name="world") -> str: | |
return f"hello, {name}" |
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 handofcats import as_command | |
@as_command | |
def nums() -> list: | |
return list(range(10)) |
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 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)] |
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
def _output(x): | |
import json | |
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)] |
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
--- output.full.py 2020-02-08 20:46:14.000000000 +0900 | |
+++ output.simple.py 2020-02-08 20:46:14.000000000 +0900 | |
@@ -1,13 +1,13 @@ | |
-import typing as t | |
+ | |
def hello(*, name="world") -> str: | |
return f"hello, {name}" | |
-def main(argv: t.Optional[t.List[str]] = None) -> t.Any: | |
+def main(argv=None): | |
import argparse | |
- parser = argparse.ArgumentParser(prog=hello.__name__, description=hello.__doc__, formatter_class=type('_HelpFormatter', (argparse.ArgumentDefaultsHelpFormatter, argparse.RawTextHelpFormatter), {})) | |
+ parser = argparse.ArgumentParser(prog=hello.__name__, description=hello.__doc__) | |
parser.print_usage = parser.print_help # type: ignore | |
parser.add_argument('--name', required=False, default='world', help='-') | |
args = parser.parse_args(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
00: | |
python $(shell echo $@*.py) | |
01: | |
python $(shell echo $@*.py) | |
02: | |
python $(shell echo $@*.py) | |
03: | |
python -m handofcats $(shell echo $@*.py) people --cont=$(shell echo $@*.py):_output | |
diff: | |
python 00*.py --expose > output.full.py | |
python 00*.py --expose --simple > output.simple.py | |
diff -u output.full.py output.simple.py |
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
import typing as t | |
def hello(*, name="world") -> str: | |
return f"hello, {name}" | |
def main(argv: t.Optional[t.List[str]] = None) -> t.Any: | |
import argparse | |
parser = argparse.ArgumentParser(prog=hello.__name__, description=hello.__doc__, formatter_class=type('_HelpFormatter', (argparse.ArgumentDefaultsHelpFormatter, argparse.RawTextHelpFormatter), {})) | |
parser.print_usage = parser.print_help # type: ignore | |
parser.add_argument('--name', required=False, default='world', help='-') | |
args = parser.parse_args(argv) | |
params = vars(args).copy() | |
return hello(**params) | |
if __name__ == '__main__': | |
main() |
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
def hello(*, name="world") -> str: | |
return f"hello, {name}" | |
def main(argv=None): | |
import argparse | |
parser = argparse.ArgumentParser(prog=hello.__name__, description=hello.__doc__) | |
parser.print_usage = parser.print_help # type: ignore | |
parser.add_argument('--name', required=False, default='world', help='-') | |
args = parser.parse_args(argv) | |
params = vars(args).copy() | |
return hello(**params) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment