Skip to content

Commit

Permalink
Merge pull request #11 from ionos-cloud/fix/indent-confirm-init
Browse files Browse the repository at this point in the history
fix: use 4 as indent for json, added confirmation before init
  • Loading branch information
rmocanu-ionos authored Feb 29, 2024
2 parents 96fbeab + 6618157 commit a3be0de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
28 changes: 23 additions & 5 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
}
}
}
2 changes: 1 addition & 1 deletion src/renderers/json-renderer.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions test/services/codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
Expand Down Expand Up @@ -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
`
Expand Down

0 comments on commit a3be0de

Please sign in to comment.