Skip to content

Commit

Permalink
feat: label validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 15, 2022
1 parent d11d159 commit 9227d9b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commands/generate/metadata/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
picklistPrompts,
} from '../../../shared/prompts/prompts';
import { relationshipFieldPrompts } from '../../../shared/prompts/relationshipField';
import { labelValidation } from '../../../shared/flags';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.load('@salesforce/plugin-sobject', 'generate.field', [
Expand Down Expand Up @@ -108,6 +109,7 @@ export default class FieldGenerate extends SfCommand<FieldGenerateResult> {
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
}),
// this a dir and not an API name to support 1 object being in multiple package directories
object: Flags.directory({
Expand Down
2 changes: 2 additions & 0 deletions src/commands/generate/metadata/platformevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AnyJson } from '@salesforce/ts-types';
import { apiNamePrompt, descriptionPrompt, directoryPrompt, pluralPrompt } from '../../../shared/prompts/prompts';
import { writeObjectFile } from '../../../shared/fs';
import { SaveablePlatformEvent } from '../../../shared/types';
import { labelValidation } from '../../../shared/flags';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.load('@salesforce/plugin-sobject', 'generate.event', [
Expand Down Expand Up @@ -39,6 +40,7 @@ export default class ObjectGenerate extends SfCommand<PlatformEventGenerateResul
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
}),
};

Expand Down
2 changes: 2 additions & 0 deletions src/commands/generate/metadata/sobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../../shared/prompts/prompts';
import { writeObjectFile } from '../../../shared/fs';
import { SaveableCustomObject, NameFieldResponse } from '../../../shared/types';
import { labelValidation } from '../../../shared/flags';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.load('@salesforce/plugin-sobject', 'generate.object', [
Expand Down Expand Up @@ -62,6 +63,7 @@ export default class ObjectGenerate extends SfCommand<CustomObjectGenerateResult
char: 'l',
summary: messages.getMessage('flags.label.summary'),
required: true,
parse: (label) => labelValidation(label),
}),
'use-default-features': Flags.boolean({
char: 'f',
Expand Down
14 changes: 14 additions & 0 deletions src/shared/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// eslint-disable-next-line @typescript-eslint/require-await
export const labelValidation = async (label: string): Promise<string> => {
if (label.length < 2) {
throw new Error(`Label must be at least ${2} characters`);
}
return label;
};

0 comments on commit 9227d9b

Please sign in to comment.