Animated Circular Progress Bar0
Font.Lokio
CLI

Template Management

Complete guide to managing templates in Lokio CLI


Parameters#

Parameters are inputs asked from the user when running lokio gen. Parameters are defined in lokio/configs.yaml and can be used inside .lokio files.

The name parameter is always available automatically — you don't need to define it.


Parameter Types#

1. Text (string)#

Free-form text input.

parameters:
  - name: description
    type: string
    required: false
    prompt: "Short description (optional):"
    default: "No description"

During lokio gen:

◇  Short description (optional):
│  Handles user authentication

In template:

/**
 * <%= description %>
 */
export class <%= pascalCase(name) %>Service {}

2. Yes / No (boolean)#

Yes/no toggle.

parameters:
  - name: useAsync
    type: boolean
    required: true
    prompt: "Use async/await?"
    default: true

During lokio gen:

◇  Use async/await?
│  Yes

In template:

<% if (useAsync === 'TRUE') { %>
async findAll(): Promise<any[]> {
<% } else { %>
findAll(): any[] {
<% } %>
  return [];
}

Boolean values in templates become the string "TRUE" or "FALSE".


3. Number (number)#

Numeric input.

parameters:
  - name: port
    type: number
    required: false
    prompt: "Port number:"
    default: 3000

In template:

app.listen(<%= port %>);
// Result: app.listen(3000);

4. Options List (options)#

User selects from a predefined list.

parameters:
  - name: type
    type: options
    required: true
    prompt: "Controller type:"
    options:
      - http
      - grpc
      - queue
    default: http

During lokio gen:

◇  Controller type:
│  ● http
│  ○ grpc
│  ○ queue

In template:

<% if (type === 'http') { %>
@Controller()
export class <%= pascalCase(name) %>Controller {}
<% } else if (type === 'grpc') { %>
export class <%= pascalCase(name) %>GrpcHandler {}
<% } %>

Defining Parameters in configs.yaml#

Full Example#

# lokio/configs.yaml
 
templates:
  - name: service
    description: NestJS service class
    path: service.lokio
    output: src/services/<%= pascalCase(name) %>Service.ts
    parameters:
      - name: name
        type: string
        required: true
        prompt: "Service name:"
 
      - name: useAsync
        type: boolean
        required: true
        prompt: "Use async/await?"
        default: true
 
      - name: type
        type: options
        required: true
        prompt: "Service type:"
        options:
          - basic
          - repository
          - external-api
        default: basic
 
      - name: description
        type: string
        required: false
        prompt: "Description (optional):"
        default: ""

Using Parameters in Templates#

Direct Insertion#

// Parameter: name = "UserOrder"
export class <%= pascalCase(name) %>Service {}
// Result: export class UserOrderService {}

In Conditions#

<% if (type === 'repository') { %>
constructor(
  @InjectRepository(<%= pascalCase(name) %>)
  private repo: Repository<<%= pascalCase(name) %>>
) {}
<% } %>

In Comments#

/**
 * @description <%= description %>
 * @generated <%= new Date().getFullYear() %>
 */

Adding Parameters via CLI#

During lokio add, select "Add extra input variables besides 'name'?"

Or edit lokio/configs.yaml directly:

parameters:
  - name: layer         # variable name in template
    type: options
    required: true
    prompt: "Which layer?"   # question shown to the user
    options:
      - domain
      - application
      - infrastructure

Or add via lokio edit <template-name> → select ParametersAdd new parameter.


Prompt Order#

required: true parameters are always asked first, then optional ones. The order in configs.yaml determines the prompt order for parameters at the same level.


Tips#

Pre-fill the First Parameter#

The first parameter can be filled directly from the command line:

lokio g service User
# 'User' automatically becomes the value of the first parameter (name)

Default Value#

If the user doesn't fill in an optional parameter, the default value is used:

- name: description
  type: string
  required: false
  prompt: "Description:"
  default: "Generated by Lokio"

User just presses Enter → the default value is applied.