Skip to content

Latest commit

 

History

History
80 lines (54 loc) · 2.85 KB

usage.md

File metadata and controls

80 lines (54 loc) · 2.85 KB

Usage

Before reading the usage make sure you understand what templates (See templates) are in tmplt

Creating new Template

To use tmplt, users need to first create or import a template. Running tmplt init <template_name> will generate a new template with the provided name, which you can then find in the directory home_dir/.tmplt/templates. You can modify this template using a text editor.

Lets create a new flask app template using tmplt

$ tmplt init flask-app

This will create a new template named "flask-app" in the home_dir/.tmplt/templates directory.

Modify the contents of the template

# Flask Project Template

# Template information
name: Flask Project
description: A template for creating a Flask project

# Dependency information
dependencies:
  - name: Flask
    install_command: pip install flask

# Files to generate
files:
  - name: app.py
    content: |
      from flask import Flask

      app = Flask(__name__)

      @app.route("/")
      def hello_world():
          return "<p>Hello, World from {app_name}!</p>"

      if __name__ == "__main__":
          app.run()


# Variables
variables:
  - name: app_name
    description: The name of the Flask app
    default: my_flask_app

Create a new project

To create a new project using a template, users can run the tmplt create <proj_name> <template_to_use> command. This command will create a new directory for your project with the <proj_name>, generate all the files, download all the dependencies and run all the post and setup commands specified in the template.

If the template has any variables, tmplt will prompt you to provide a value for each variable. You can choose to use the default value or provide a new value.

Let's use our flask template to create a new flask project:

$ tmplt create myflaskapp flask-app

This will create a new directory with the name myflaskapp, based on the flask-app template you created earlier. The command will prompt you to provide a value for the app_name variable.

Import a Template

In addition to being able to create your own templates, users can also import templates created by other users!

The tmplt import <url> <template_name_to_save_as> command is used to import a template from a URL. Running tmplt import will download the template from the URL and save it with the name you provided.

You can then use the imported template to create a new project as showed in the Create a new project section

List Available Templates

This command is used to list all the available templates. Running tmplt list will display a list of all the templates that you can use to create projects.

tmplt list

That's it! With these simple commands, you can use tmplt to create and manage projects based on templates.