生成代码而不编写任何代码。
generoo的Python项目详细描述
大方
当我们开始新的项目时,我们经常会经历一系列类似的步骤来引导它。作为开发人员,我们希望 花时间发展。这就是慷慨解囊的地方。慷慨允许开发人员编写一次项目模板 然后在几秒钟内从该模板生成新项目。无需任何额外编码的项目模板提供了时间 回到开发人员那里,这样他们就可以专注于编写核心业务逻辑。
要深入了解大方及其用途,请参见documentation。
安装
PIP
从pip安装软件包:
pip install generoo
从模块运行:
python -m generoo <goal> <scope> <name>
来源
克隆项目。导航到计算机上的目录。
note:gloono必须在python 3.6及更高版本中运行。
您可以使用以下命令从python解释器运行:
python generoo.py <goal> <scope> <name>
它是如何工作的?
大方很简单。使用Mustache的语法创建用于字符串替换的模板。
模板可以是一个名为examples/hello-world/hello_world.py
的文件,看起来像:
print('Hello, {{who}}')
然后,json或yaml中的模板配置文件定义了用户运行gloono时的提示。这里有一个例子
文件名为examples/hello-world/template-config.json
:
{"prompts":[{"name":"who","text":"Enter who you want to say hello to"}]}
文本是显示提示时用户将看到的内容,名称是将被替换的模板值。
运行python3 generoo.py generate project hello-world --template examples/hello-world/hello_world.py --template-config examples/hello-world/template-config.json
将提示用户:
$ Say hello to:
当用户输入:World
时,模板将被填写并写入hello-world/hello_world.py
,看起来像:
print('Hello, World')
有关模板系统如何工作的更多信息,请参见Generoo documentation。
用法
使用大方很简单。cli或python脚本接受3个位置参数:
generoo <goal> <scope> <name> [options...]
goal
-你想要大方做什么。示例:generate
scope
-你想要大方创造的东西。示例:project
name
-你想命名什么是慷慨创造。这将用作根目录名。示例:example
位置参数(按显示顺序):
目标
Argument | Description | Aliases |
---|---|---|
^{ | Fill in templates for an archetype or custom user project. | ^{ |
范围
Argument | Description | Aliases |
---|---|---|
^{ | Generates a new project with the given name. | ^{ |
选项
Option | Description |
---|---|
^{ | Will run generoo without a pre-existing configuration. |
^{ | Will run generoo using the pre-existing configuration and only prompt for values not present in the configuration. |
^{ | Points to a location on the system that contains a custom template config. |
^{ | Points to a directory on the system that contains templates for a corresponding template config. |
^{ | Points to a file on the system that contains a run configuration for a corresponding template config. |
内置模板
如果没有给出--template
或--template-config
参数,则大方将从其内置模板生成。
查看archetypes
目录,亲自查看模板。或者,更好的是,尝试生成一个。
贡献
有你想分享的模板吗?提交一份带有模板的公关文件,我们将看到如何获得它 在该项目的内置模板中。
想要一些新功能吗?打开一个问题或公关与你想看到的变化。