diff --git a/src/commands/init.ts b/src/commands/init.ts index 18a8eb6..47d1b8b 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -2,6 +2,8 @@ import { Codex } from '../services/codex' import BaseCommand from '../base/base-command' import { flags } from '@oclif/command' import renderers from '../renderers' +import ui from '../services/ui' +import config from '../services/config' export default class Init extends BaseCommand { static description = 'initialize a codex project in S3' @@ -27,10 +29,26 @@ export default class Init extends BaseCommand { }] async run() { - const codex = new Codex() - await codex.init({ - specUrl: this.args.url, - format: this.flags.format - }) + ui.warning(`bucket ${config.get('s3.bucket')} will be reset`) + + const { Toggle } = require('enquirer') + + const prompt = new Toggle({ + message: `Are you sure you want to init the current bucket (${config.get('s3.bucket')})?`, + enabled: 'Yes', + disabled: 'No' + }); + + const answer = await prompt.run() + + if (answer) { + const codex = new Codex() + await codex.init({ + specUrl: this.args.url, + format: this.flags.format + }) + } else { + ui.info('bailing out') + } } } diff --git a/src/renderers/json-renderer.ts b/src/renderers/json-renderer.ts index fb26dde..046072a 100644 --- a/src/renderers/json-renderer.ts +++ b/src/renderers/json-renderer.ts @@ -1,4 +1,4 @@ -export const DEFAULT_INDENT = 2 +export const DEFAULT_INDENT = 4 export default { marshal: function (object: any, indent: number = DEFAULT_INDENT): string { diff --git a/test/services/codex.test.ts b/test/services/codex.test.ts index d16bad6..232d8f4 100644 --- a/test/services/codex.test.ts +++ b/test/services/codex.test.ts @@ -267,14 +267,14 @@ describe('codex tests', async () => { --- swagger.json +++ swagger.json @@ -2,7 +2,8 @@ - "swagger": "2.0", - "info": { - "description": "Some description", - "version": "5.0", -- "title": "CLOUD API" -+ "${swagger.sdkPatchLevelAttr}": 1, -+ "title": "CLOUD API changed" - } + "swagger": "2.0", + "info": { + "description": "Some description", + "version": "5.0", +- "title": "CLOUD API" ++ "${swagger.sdkPatchLevelAttr}": 1, ++ "title": "CLOUD API changed" + } } \\ No newline at end of file ` @@ -323,15 +323,15 @@ describe('codex tests', async () => { --- swagger.json +++ swagger.json @@ -2,8 +2,8 @@ - "swagger": "2.0", - "info": { - "description": "Some description", - "version": "5.0", -- "${swagger.sdkPatchLevelAttr}": 1, -- "title": "CLOUD API" -+ "${swagger.sdkPatchLevelAttr}": 2, -+ "title": "CLOUD API changed" - } + "swagger": "2.0", + "info": { + "description": "Some description", + "version": "5.0", +- "${swagger.sdkPatchLevelAttr}": 1, +- "title": "CLOUD API" ++ "${swagger.sdkPatchLevelAttr}": 2, ++ "title": "CLOUD API changed" + } } \\ No newline at end of file `