Skip to content

Commit

Permalink
refactor(core)!: Remove legacy --file flag for execute CLI command (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Apr 5, 2024
1 parent ff81de3 commit 4052b6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
12 changes: 11 additions & 1 deletion packages/cli/BREAKING-CHANGES.md
Expand Up @@ -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?

Expand Down
43 changes: 8 additions & 35 deletions packages/cli/src/commands/execute.ts
@@ -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';

Expand All @@ -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',
}),
Expand All @@ -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
Expand Down

0 comments on commit 4052b6c

Please sign in to comment.