From 96e11c169cde65194c1136e6b40c1bbea35c813a Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 20 Apr 2026 14:47:58 +0200 Subject: create cli --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..20781d1 --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# Blueprint + +Write your project templates using lua. + +## Creating your own templates + +A _template_ is just a directory containing at least one `build.lua` file +which describes to structure of the template. Then you can add files and directories +that should be created when creating a instance of the template. + +Here is a simple example: + +```lua +-- build.lua +local template = Template:new() + +template:add_file("./test.py", { + module = "a_module_that_is_different", + name = template:option('name') +}) + +return template +``` + +Then the same directory will contain the `test.py` we added in the template: + +```py +#!/usr/bin/env python3 + +# This module is called @{name()} + +import @{module} + +print("@{function() + return "Hello World" +end}") + +print("@{function() + local a = { "asdf", "1234" } + return a[1] +end}") + +print(@{function() + local a = { "asdf", "1234" } -- { + return a[2] +end}) + +print("@{function() + local a = "asdf{asdf" + return a:sub(1) +end}") + +print("@{function() + local a = "asdf" + --[[ + some comment } + --]] + return a +end}") + +print("@{function() + local a = [[ + some comment } + ]] + return a:sub(2, 8) +end}") +``` + +As you can see you can now run lua-code inside of the `@{...}` sections. +The last table argument of the `add_file` function are functions or values you want to bind to the global scope of the macros and you want to use inside of the template file. + +### Creating additional options + +You can create additional command line arguments by calling `template:option('')`. This returns a function which you can bind to the scripting environment like we did in the example above with the _name_ option. + +If you want to set a default value for an option, make it not required or add a description you can do that with the `template:set_option('', '', '', '')` function. -- cgit v1.2.3-70-g09d2