Skip to content

Commit

Permalink
fix: prevent empty names
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Feb 13, 2025
1 parent 023241d commit fdee546
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/commands/CreateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class CreateCommand extends BaseCommand<CreateCommandArgs> {
.option("client-secret", { type: "string" })
.check((argv) => {
if (argv.name === "all") return "The name 'all' is reserved."
if (argv.name.trim().length === 0) return "The name cannot be empty."
return true
})

Expand All @@ -32,19 +33,21 @@ export class CreateCommand extends BaseCommand<CreateCommandArgs> {
process.exit(1)
}

if (this._config.existsConnector(args.name)) {
console.error(`A connector with the name ${chalk.red(args.name)} already exists.`)
const name = args.name.trim()

if (this._config.existsConnector(name)) {
console.error(`A connector with the name ${chalk.red(name)} already exists.`)
process.exit(1)
}

console.log("Creating connector...")

const connector = this._config.addConnector(args.version, args.name, args.dbConnectionString, args.baseUrl, args.clientId, args.clientSecret)
const connector = this._config.addConnector(args.version, name, args.dbConnectionString, args.baseUrl, args.clientId, args.clientSecret)
await this._config.save()

await this._processManager.start(args.name)
await this._processManager.start(name)

console.log(`Successfully created the connector ${chalk.green(args.name)}.\n`)
console.log(`Successfully created the connector ${chalk.green(name)}.\n`)

await this.showInstances([connector])
}
Expand Down

0 comments on commit fdee546

Please sign in to comment.