diff --git a/src/commands/features/create.test.ts b/src/commands/features/create.test.ts index 1e4b417f5..1884e2983 100644 --- a/src/commands/features/create.test.ts +++ b/src/commands/features/create.test.ts @@ -136,7 +136,11 @@ describe('features create', () => { ]) .it('returns a new feature with quick create', (ctx) => { - expect(JSON.parse(ctx.stdout)).to.eql(mockFeature) + const jsonStartIndex = ctx.stdout.indexOf('{') + const jsonEndIndex = ctx.stdout.lastIndexOf('}') + const jsonString = ctx.stdout.slice(jsonStartIndex, jsonEndIndex + 1) + const parsedJson = JSON.parse(jsonString) + expect(parsedJson).to.eql(mockFeature) }) dvcTest() @@ -309,7 +313,11 @@ describe('features create', () => { ]) .it('returns a new feature with quick create not in headless mode', (ctx) => { - expect(JSON.parse(ctx.stdout)).to.eql(mockFeature) + const jsonStartIndex = ctx.stdout.indexOf('{') + const jsonEndIndex = ctx.stdout.lastIndexOf('}') + const jsonString = ctx.stdout.slice(jsonStartIndex, jsonEndIndex + 1) + const parsedJson = JSON.parse(jsonString) + expect(parsedJson).to.eql(mockFeature) }) // dvcTest() diff --git a/src/commands/features/create.ts b/src/commands/features/create.ts index b0f940cb2..2d97fd919 100644 --- a/src/commands/features/create.ts +++ b/src/commands/features/create.ts @@ -3,11 +3,11 @@ import { descriptionPrompt, getSdkVisibilityPrompt, keyPrompt, namePrompt } from import CreateCommand from '../createCommand' import { VariableListOptions } from '../../ui/prompts/listPrompts/variablesListPrompt' import { Flags } from '@oclif/core' -import { CreateFeatureDto } from '../../api/schemas' +import { CreateFeatureDto, Feature } from '../../api/schemas' import { VariationListOptions } from '../../ui/prompts/listPrompts/variationsListPrompt' -import { - mergeQuickFeatureParamsWithAnswers, - setupTargetingForEnvironments +import { + mergeQuickFeatureParamsWithAnswers, + setupTargetingForEnvironments } from '../../utils/features/quickCreateFeatureUtils' import { fetchProject } from '../../api/projects' @@ -53,6 +53,7 @@ export default class CreateFeature extends CreateCommand { const feature = await createFeature(this.authToken, this.projectKey, featureParams) await setupTargetingForEnvironments(this.authToken, this.projectKey, feature.key) this.writer.showResults(feature) + this.showSuggestedCommand(feature) return } @@ -78,4 +79,12 @@ export default class CreateFeature extends CreateCommand { const result = await createFeature(this.authToken, this.projectKey, params) this.writer.showResults(result) } + + private showSuggestedCommand(feature: Feature) { + const message = `\nFeature "${feature.name}" successfully created!\n` + + '\nTo update the targeting rules, use: \n\n' + + ` dvc targeting update ${feature.key}\n` + + this.writer.showRawResults(message) + } }