Skip to content

Commit 7d3291f

Browse files
authored
refactor(cli): explicit BaseCommand log method names (#6335)
1 parent 7052506 commit 7d3291f

File tree

12 files changed

+50
-48
lines changed

12 files changed

+50
-48
lines changed

packages/libraries/cli/src/base-command.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ export default abstract class BaseCommand<T extends typeof Command> extends Comm
5252
this.args = args as Args<T>;
5353
}
5454

55-
success(...args: any[]) {
55+
logSuccess(...args: any[]) {
5656
this.log(Texture.success(...args));
5757
}
5858

59-
fail(...args: any[]) {
59+
logFailure(...args: any[]) {
6060
this.log(Texture.failure(...args));
6161
}
6262

63-
info(...args: any[]) {
63+
logInfo(...args: any[]) {
6464
this.log(Texture.info(...args));
6565
}
6666

67-
infoWarning(...args: any[]) {
67+
logWarning(...args: any[]) {
6868
this.log(Texture.warning(...args));
6969
}
7070

packages/libraries/cli/src/commands/app/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class AppCreate extends Command<typeof AppCreate> {
116116
? affectedOperation.body.substring(0, maxCharacters) + '...'
117117
: affectedOperation.body
118118
).replace(/\n/g, '\\n');
119-
this.infoWarning(
119+
this.logWarning(
120120
`Failed uploading document: ${result.addDocumentsToAppDeployment.error.details.message}` +
121121
`\nOperation hash: ${affectedOperation?.hash}` +
122122
`\nOperation body: ${truncatedBody}`,

packages/libraries/cli/src/commands/config/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export default class DeleteConfig extends Command<typeof DeleteConfig> {
1515
async run() {
1616
const { args } = await this.parse(DeleteConfig);
1717
this._userConfig!.delete(args.key);
18-
this.success(Texture.boldQuotedWords(`Config flag "${args.key}" was deleted`));
18+
this.logSuccess(Texture.boldQuotedWords(`Config flag "${args.key}" was deleted`));
1919
}
2020
}

packages/libraries/cli/src/commands/config/reset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default class ResetConfig extends Command<typeof ResetConfig> {
55

66
async run() {
77
this.userConfig.clear();
8-
this.success('Config cleared.');
8+
this.logSuccess('Config cleared.');
99
}
1010
}

packages/libraries/cli/src/commands/config/set.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default class SetConfig extends Command<typeof SetConfig> {
2222
async run() {
2323
const { args } = await this.parse(SetConfig);
2424
this.userConfig.set(args.key as ValidConfigurationKeys, args.value);
25-
this.success(Texture.boldQuotedWords(`Config flag "${args.key}" was set to "${args.value}"`));
25+
this.logSuccess(
26+
Texture.boldQuotedWords(`Config flag "${args.key}" was set to "${args.value}"`),
27+
);
2628
}
2729
}

packages/libraries/cli/src/commands/dev.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default class Dev extends Command<typeof Dev> {
216216
write: flags.write,
217217
unstable__forceLatest,
218218
onError: message => {
219-
this.fail(message);
219+
this.logFailure(message);
220220
},
221221
}),
222222
);
@@ -229,7 +229,7 @@ export default class Dev extends Command<typeof Dev> {
229229
services,
230230
write: flags.write,
231231
onError: message => {
232-
this.fail(message);
232+
this.logFailure(message);
233233
},
234234
}),
235235
);
@@ -329,7 +329,7 @@ export default class Dev extends Command<typeof Dev> {
329329
return;
330330
}
331331

332-
this.success('Composition successful');
332+
this.logSuccess('Composition successful');
333333
this.log(`Saving supergraph schema to ${input.write}`);
334334
await writeFile(resolve(process.cwd(), input.write), compositionResult.supergraphSdl, 'utf-8');
335335
}
@@ -387,7 +387,7 @@ export default class Dev extends Command<typeof Dev> {
387387
return;
388388
}
389389

390-
this.success('Composition successful');
390+
this.logSuccess('Composition successful');
391391
this.log(`Saving supergraph schema to ${input.write}`);
392392
await writeFile(resolve(process.cwd(), input.write), compositionResult.supergraphSdl, 'utf-8');
393393
}
@@ -397,12 +397,12 @@ export default class Dev extends Command<typeof Dev> {
397397
serviceInputs: ServiceInput[],
398398
compose: (services: Service[]) => Promise<void>,
399399
) {
400-
this.info('Watch mode enabled');
400+
this.logInfo('Watch mode enabled');
401401

402402
let services = await this.resolveServices(serviceInputs);
403403
await compose(services);
404404

405-
this.info('Watching for changes');
405+
this.logInfo('Watching for changes');
406406

407407
let resolveWatchMode: () => void;
408408

@@ -419,25 +419,25 @@ export default class Dev extends Command<typeof Dev> {
419419
service => services.find(s => s.name === service.name)!.sdl !== service.sdl,
420420
)
421421
) {
422-
this.info('Detected changes, recomposing');
422+
this.logInfo('Detected changes, recomposing');
423423
await compose(newServices);
424424
services = newServices;
425425
}
426426
} catch (error) {
427-
this.fail(String(error));
427+
this.logFailure(String(error));
428428
}
429429

430430
timeoutId = setTimeout(watch, watchInterval);
431431
};
432432

433433
process.once('SIGINT', () => {
434-
this.info('Exiting watch mode');
434+
this.logInfo('Exiting watch mode');
435435
clearTimeout(timeoutId);
436436
resolveWatchMode();
437437
});
438438

439439
process.once('SIGTERM', () => {
440-
this.info('Exiting watch mode');
440+
this.logInfo('Exiting watch mode');
441441
clearTimeout(timeoutId);
442442
resolveWatchMode();
443443
});

packages/libraries/cli/src/commands/introspect.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class Introspect extends Command<typeof Introspect> {
4747
method: 'POST',
4848
}).catch(err => {
4949
if (err instanceof GraphQLError) {
50-
this.fail(err.message);
50+
this.logFailure(err.message);
5151
this.exit(1);
5252
}
5353

@@ -57,7 +57,7 @@ export default class Introspect extends Command<typeof Introspect> {
5757
});
5858

5959
if (!schema) {
60-
this.fail('Unable to load schema');
60+
this.logFailure('Unable to load schema');
6161
this.exit(1);
6262
}
6363

@@ -89,11 +89,11 @@ export default class Introspect extends Command<typeof Introspect> {
8989
break;
9090
}
9191
default:
92-
this.fail(`Unsupported file extension ${extname(flags.write)}`);
92+
this.logFailure(`Unsupported file extension ${extname(flags.write)}`);
9393
this.exit(1);
9494
}
9595

96-
this.success(`Saved to ${filepath}`);
96+
this.logSuccess(`Saved to ${filepath}`);
9797
}
9898
}
9999
}

packages/libraries/cli/src/commands/operations/check.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class OperationsCheck extends Command<typeof OperationsCheck> {
117117
});
118118

119119
if (operations.length === 0) {
120-
this.info('No operations found');
120+
this.logInfo('No operations found');
121121
this.exit(0);
122122
return;
123123
}
@@ -160,7 +160,7 @@ export default class OperationsCheck extends Command<typeof OperationsCheck> {
160160
const operationsWithErrors = invalidOperations.filter(o => o.errors.length > 0);
161161

162162
if (operationsWithErrors.length === 0) {
163-
this.success(`All operations are valid (${operations.length})`);
163+
this.logSuccess(`All operations are valid (${operations.length})`);
164164
this.exit(0);
165165
return;
166166
}
@@ -184,7 +184,7 @@ export default class OperationsCheck extends Command<typeof OperationsCheck> {
184184
if (error instanceof Errors.ExitError) {
185185
throw error;
186186
} else {
187-
this.fail('Failed to validate operations');
187+
this.logFailure('Failed to validate operations');
188188
this.handleFetchError(error);
189189
}
190190
}
@@ -197,7 +197,7 @@ export default class OperationsCheck extends Command<typeof OperationsCheck> {
197197
}
198198

199199
private renderErrors(sourceName: string, errors: GraphQLError[]) {
200-
this.fail(sourceName);
200+
this.logFailure(sourceName);
201201
errors.forEach(e => {
202202
this.log(` - ${Texture.boldQuotedWords(e.message)}`);
203203
});

packages/libraries/cli/src/commands/schema/check.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
236236
if (result.schemaCheck.__typename === 'SchemaCheckSuccess') {
237237
const changes = result.schemaCheck.changes;
238238
if (result.schemaCheck.initial) {
239-
this.success('Schema registry is empty, nothing to compare your schema with.');
239+
this.logSuccess('Schema registry is empty, nothing to compare your schema with.');
240240
} else if (!changes?.total) {
241-
this.success('No changes');
241+
this.logSuccess('No changes');
242242
} else {
243243
this.log(renderChanges(changes));
244244
}
@@ -272,20 +272,20 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
272272
this.log('');
273273

274274
if (forceSafe) {
275-
this.success('Breaking changes were expected (forced)');
275+
this.logSuccess('Breaking changes were expected (forced)');
276276
} else {
277277
this.exit(1);
278278
}
279279
} else if (result.schemaCheck.__typename === 'GitHubSchemaCheckSuccess') {
280-
this.success(result.schemaCheck.message);
280+
this.logSuccess(result.schemaCheck.message);
281281
} else {
282282
this.error(result.schemaCheck.message);
283283
}
284284
} catch (error) {
285285
if (error instanceof Errors.ExitError) {
286286
throw error;
287287
} else {
288-
this.fail('Failed to check schema');
288+
this.logFailure('Failed to check schema');
289289
this.handleFetchError(error);
290290
}
291291
}

packages/libraries/cli/src/commands/schema/delete.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class SchemaDelete extends Command<typeof SchemaDelete> {
9494
);
9595

9696
if (!confirmed) {
97-
this.info('Aborting');
97+
this.logInfo('Aborting');
9898
this.exit(0);
9999
}
100100
}
@@ -125,12 +125,12 @@ export default class SchemaDelete extends Command<typeof SchemaDelete> {
125125
});
126126

127127
if (result.schemaDelete.__typename === 'SchemaDeleteSuccess') {
128-
this.success(`${service} deleted`);
128+
this.logSuccess(`${service} deleted`);
129129
this.exit(0);
130130
return;
131131
}
132132

133-
this.fail(`Failed to delete ${service}`);
133+
this.logFailure(`Failed to delete ${service}`);
134134
const errors = result.schemaDelete.errors;
135135

136136
if (errors) {
@@ -141,7 +141,7 @@ export default class SchemaDelete extends Command<typeof SchemaDelete> {
141141
if (error instanceof Errors.ExitError) {
142142
throw error;
143143
} else {
144-
this.fail(`Failed to complete`);
144+
this.logFailure(`Failed to complete`);
145145
this.handleFetchError(error);
146146
}
147147
}

0 commit comments

Comments
 (0)