Variable: buildCLIEntrypoint
constbuildCLIEntrypoint: (entrypoint) =>CLIEntrypoint
Type a CLI entrypoint in the style of lakutata 2.x; the function is returned as it is.
Parameters
entrypoint
The function the entrypoint calls when it starts, with the module, the commands, the request handler and the destroyer registrar.
Returns
The same function, to give to the cli option of buildEntrypoints.
Example
typescript
import {Application} from 'lakutata'
import {buildCLIEntrypoint, buildEntrypoints, CLIContext, Controller} from 'lakutata/com/entrypoint'
import {CLIAction} from 'lakutata/decorator/ctrl'
class VersionController extends Controller {
@CLIAction('version')
public async version(): Promise<string> {
return '1.0.0'
}
}
Application.run(() => ({
id: 'tool.app',
name: 'Tool',
components: {
entrypoint: buildEntrypoints({
controllers: [VersionController],
//Run the command given as the first argument once the entrypoint starts
cli: buildCLIEntrypoint(async (module, cliMap, handler): Promise<void> => {
const command: string = process.argv[2] ?? 'version'
if (cliMap.has(command)) console.log(await handler(new CLIContext({command: command, data: {}})))
})
})
},
bootstrap: ['entrypoint']
}))