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
nameparameter 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: trueDuring 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: 3000In 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: httpDuring 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
- infrastructureOr add via lokio edit <template-name> → select Parameters → Add 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.