2021-08-29 11:58:11 -07:00
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
import { Command, flags } from '@oclif/command';
|
2021-07-01 00:04:24 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
import { IDataObject } from 'n8n-workflow';
|
2021-07-01 00:04:24 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
import { Db } from '../../src';
|
2021-07-01 00:04:24 -07:00
|
|
|
|
|
|
|
export class ListWorkflowCommand extends Command {
|
|
|
|
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.',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
2021-07-01 00:04:24 -07:00
|
|
|
async run() {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
2021-07-01 00:04:24 -07:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await Db.init();
|
|
|
|
|
|
|
|
const findQuery: IDataObject = {};
|
|
|
|
if (flags.active !== undefined) {
|
|
|
|
findQuery.active = flags.active === 'true';
|
|
|
|
}
|
|
|
|
|
2022-04-14 00:02:12 -07:00
|
|
|
const workflows = await Db.collections.Workflow.find(findQuery);
|
2021-07-01 00:04:24 -07:00
|
|
|
if (flags.onlyId) {
|
2021-08-29 11:58:11 -07:00
|
|
|
workflows.forEach((workflow) => console.log(workflow.id));
|
2021-07-01 00:04:24 -07:00
|
|
|
} else {
|
2021-08-29 11:58:11 -07:00
|
|
|
workflows.forEach((workflow) => console.log(`${workflow.id}|${workflow.name}`));
|
2021-07-01 00:04:24 -07:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error('\nGOT ERROR');
|
|
|
|
console.log('====================================');
|
|
|
|
console.error(e.message);
|
|
|
|
console.error(e.stack);
|
|
|
|
this.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.exit();
|
|
|
|
}
|
|
|
|
}
|