Files
n8n-enterprise-unlocked/packages/cli/src/commands/list/workflow.ts
T
कारतोफ्फेलस्क्रिप्ट™ 000e76e3b4 ci(core): Reduce memory usage in tests (part-2) (no-changelog) (#7671)
This also gets rid of `Db.collection`, which was another source of
circular dependencies.
2023-11-10 15:04:26 +01:00

55 lines
1.7 KiB
TypeScript

import { flags } from '@oclif/command';
import type { FindOptionsWhere } from 'typeorm';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { BaseCommand } from '../BaseCommand';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
import Container from 'typedi';
export class ListWorkflowCommand extends BaseCommand {
static description = '\nList workflows';
static examples = [
'$ n8n list:workflow',
'$ n8n list:workflow --active=true --onlyId',
'$ n8n list:workflow --active=false',
];
static flags = {
help: flags.help({ char: 'h' }),
active: flags.string({
description: 'Filters workflows by active status. Can be true or false',
}),
onlyId: flags.boolean({
description: 'Outputs workflow IDs only, one per line.',
}),
};
async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(ListWorkflowCommand);
if (flags.active !== undefined && !['true', 'false'].includes(flags.active)) {
this.error('The --active flag has to be passed using true or false');
}
const findQuery: FindOptionsWhere<WorkflowEntity> = {};
if (flags.active !== undefined) {
findQuery.active = flags.active === 'true';
}
const workflows = await Container.get(WorkflowRepository).findBy(findQuery);
if (flags.onlyId) {
workflows.forEach((workflow) => this.logger.info(workflow.id));
} else {
workflows.forEach((workflow) => this.logger.info(`${workflow.id}|${workflow.name}`));
}
}
async catch(error: Error) {
this.logger.error('\nGOT ERROR');
this.logger.error('====================================');
this.logger.error(error.message);
this.logger.error(error.stack!);
}
}