1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-12 18:26:16 +03:00

refactor(core)!: Remove legacy --file flag for execute CLI command (#9054)

This commit is contained in:
Iván Ovejero 2024-04-05 14:28:04 +02:00 committed by GitHub
parent ff81de3313
commit 4052b6c073
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 36 deletions

View File

@ -2,11 +2,21 @@
This list shows all the versions which include breaking changes and how to upgrade.
## 1.37.0
### What changed?
The `--file` flag for the `execute` CLI command has been removed.
### When is action necessary?
If you have scripts relying on the `--file` flag for the `execute` CLI command, update them to first import the workflow and then execute it using the `--id` flag.
## 1.32.0
### What changed?
N8n auth cookie has `Secure` flag set by default now.
n8n auth cookie has `Secure` flag set by default now.
### When is action necessary?

View File

@ -1,7 +1,5 @@
import { Container } from 'typedi';
import { Flags } from '@oclif/core';
import { promises as fs } from 'fs';
import { PLACEHOLDER_EMPTY_WORKFLOW_ID } from 'n8n-core';
import type { IWorkflowBase } from 'n8n-workflow';
import { ApplicationError, ExecutionBaseError } from 'n8n-workflow';
@ -17,13 +15,10 @@ import { OwnershipService } from '@/services/ownership.service';
export class Execute extends BaseCommand {
static description = '\nExecutes a given workflow';
static examples = ['$ n8n execute --id=5', '$ n8n execute --file=workflow.json'];
static examples = ['$ n8n execute --id=5'];
static flags = {
help: Flags.help({ char: 'h' }),
file: Flags.string({
description: 'path to a workflow file to execute',
}),
id: Flags.string({
description: 'id of the workflow to execute',
}),
@ -41,42 +36,20 @@ export class Execute extends BaseCommand {
async run() {
const { flags } = await this.parse(Execute);
if (!flags.id && !flags.file) {
this.logger.info('Either option "--id" or "--file" have to be set!');
if (!flags.id) {
this.logger.info('"--id" has to be set!');
return;
}
if (flags.id && flags.file) {
this.logger.info('Either "id" or "file" can be set never both!');
return;
if (flags.file) {
throw new ApplicationError(
'The --file flag is no longer supported. Please first import the workflow and then execute it using the --id flag.',
{ level: 'warning' },
);
}
let workflowId: string | undefined;
let workflowData: IWorkflowBase | null = null;
if (flags.file) {
// Path to workflow is given
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
workflowData = JSON.parse(await fs.readFile(flags.file, 'utf8'));
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (error.code === 'ENOENT') {
this.logger.info(`The file "${flags.file}" could not be found.`);
return;
}
throw error;
}
// Do a basic check if the data in the file looks right
// TODO: Later check with the help of TypeScript data if it is valid or not
if (workflowData?.nodes === undefined || workflowData.connections === undefined) {
this.logger.info(`The file "${flags.file}" does not contain valid workflow data.`);
return;
}
workflowId = workflowData.id ?? PLACEHOLDER_EMPTY_WORKFLOW_ID;
}
if (flags.id) {
// Id of workflow is given