Skip to content

Commit a63ac07

Browse files
fix(cli): Standardise flag names
Co-authored-by: Housein Abo Shaar <76689341+GogoIsProgramming@users.noreply.github.com>
1 parent 87fc929 commit a63ac07

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

packages/cli/e2e/add-command.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('Add Command E2E', () => {
174174

175175
it('fails when neither queryName nor mutationName is provided for API extension', async () => {
176176
await expect(performAddOperation({ apiExtension: true } as any)).rejects.toThrow(
177-
'At least one of queryName or mutationName must be specified',
177+
'At least one of query-name or mutation-name must be specified',
178178
);
179179
expect(apiExtRunSpy).not.toHaveBeenCalled();
180180
});

packages/cli/src/commands/add/add-operations.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { log } from '@clack/prompts';
2+
import pc from 'picocolors';
3+
14
import { addApiExtensionCommand } from './api-extension/add-api-extension';
25
import { addCodegenCommand } from './codegen/add-codegen';
36
import { addEntityCommand } from './entity/add-entity';
@@ -145,7 +148,7 @@ export async function performAddOperation(options: AddOperationOptions): Promise
145148
!options.selectedService.trim()
146149
) {
147150
throw new Error(
148-
'Service name is required for job queue. Usage: vendure add -j [plugin-name] --name <job-name> --selectedService <service-name>',
151+
'Service name is required for job queue. Usage: vendure add -j [plugin-name] --name <job-name> --selected-service <service-name>',
149152
);
150153
}
151154
await addJobQueueCommand.run({
@@ -191,16 +194,16 @@ export async function performAddOperation(options: AddOperationOptions): Promise
191194

192195
if (!hasValidQueryName && !hasValidMutationName) {
193196
throw new Error(
194-
'At least one of queryName or mutationName must be specified as a non-empty string. ' +
195-
'Usage: vendure add -a [plugin-name] --queryName <name> --mutationName <name>',
197+
'At least one of query-name or mutation-name must be specified as a non-empty string. ' +
198+
'Usage: vendure add -a [plugin-name] --query-name <name> --mutation-name <name>',
196199
);
197200
}
198201

199202
// If a string is passed for apiExtension, it should be a valid plugin name
200203
if (typeof options.apiExtension === 'string' && !options.apiExtension.trim()) {
201204
throw new Error(
202205
'Plugin name cannot be empty when specified. ' +
203-
'Usage: vendure add -a [plugin-name] --queryName <name> --mutationName <name>',
206+
'Usage: vendure add -a [plugin-name] --query-name <name> --mutation-name <name>',
204207
);
205208
}
206209

@@ -223,7 +226,7 @@ export async function performAddOperation(options: AddOperationOptions): Promise
223226
// If a string is passed, it should be a valid plugin name
224227
if (typeof options.uiExtensions === 'string' && !options.uiExtensions.trim()) {
225228
throw new Error(
226-
'Plugin name cannot be empty when specified. Usage: vendure add --uiExtensions [plugin-name]',
229+
'Plugin name cannot be empty when specified. Usage: vendure add --ui-extensions [plugin-name]',
227230
);
228231
}
229232
await addUiExtensionsCommand.run({
@@ -250,9 +253,24 @@ export async function performAddOperation(options: AddOperationOptions): Promise
250253
) {
251254
throw error;
252255
}
253-
return {
254-
success: false,
255-
message: error.message ?? 'Add operation failed',
256-
};
256+
// For other errors, log them in a more user-friendly way
257+
// For validation errors, show the full error with stack trace
258+
if (error.message.includes('Plugin name is required')) {
259+
// Extract error message and stack trace
260+
const errorMessage = error.message;
261+
const stackLines = error.stack.split('\n');
262+
const stackTrace = stackLines.slice(1).join('\n'); // Remove first line (error message)
263+
264+
// Display stack trace first, then colored error message at the end
265+
log.error(stackTrace);
266+
log.error(''); // Add empty line for better readability
267+
log.error(pc.red('Error:') + ' ' + String(errorMessage));
268+
} else {
269+
log.error(error.message as string);
270+
if (error.stack) {
271+
log.error(error.stack);
272+
}
273+
}
274+
process.exit(1);
257275
}
258276
}

packages/cli/src/commands/add/api-extension/add-api-extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ async function addApiExtension(
6969

7070
if (!hasValidQueryName && !hasValidMutationName) {
7171
throw new Error(
72-
'At least one of queryName or mutationName must be specified as a non-empty string in non-interactive mode.\n' +
73-
'Usage: npx vendure add -a <PluginName> --queryName <name> --mutationName <name>',
72+
'At least one of query-name or mutation-name must be specified as a non-empty string in non-interactive mode.\n' +
73+
'Usage: npx vendure add -a <PluginName> --query-name <name> --mutation-name <name>',
7474
);
7575
}
7676
}
@@ -95,7 +95,7 @@ async function addApiExtension(
9595
if (!options.selectedService || options.selectedService.trim() === '') {
9696
throw new Error(
9797
'Service must be specified in non-interactive mode.\n' +
98-
'Usage: npx vendure add -a <PluginName> --queryName <name> --mutationName <name> --selectedService <service-name>',
98+
'Usage: npx vendure add -a <PluginName> --query-name <name> --mutation-name <name> --selected-service <service-name>',
9999
);
100100
}
101101

@@ -168,7 +168,7 @@ async function addApiExtension(
168168
const mutationNameResult =
169169
options?.mutationName ??
170170
(await text({
171-
message: 'Enter a name for the new mutation',
171+
message: 'Enter a new name for the new mutation',
172172
initialValue: 'myNewMutation',
173173
}));
174174
if (!isCancel(mutationNameResult)) {

packages/cli/src/commands/command-declarations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ export const cliCommands: CliCommandDefinition[] = [
9494
required: false,
9595
subOptions: [
9696
{
97-
long: '--queryName <name>',
97+
long: '--query-name <name>',
9898
description: 'Name for the query (used with -a)',
9999
required: false,
100100
},
101101
{
102-
long: '--mutationName <name>',
102+
long: '--mutation-name <name>',
103103
description: 'Name for the mutation (used with -a)',
104104
required: false,
105105
},

0 commit comments

Comments
 (0)