move flags to its own module.

This commit is contained in:
iamBadgers
2025-06-14 17:12:49 -07:00
parent 882e8cf72a
commit aa4c44840b
2 changed files with 38 additions and 24 deletions

View File

@@ -3,38 +3,20 @@ import { MongoClient } from 'mongodb'
import { CharacterService } from './character_service'
import { DatabaseService } from './database'
import { Command } from 'commander'
// import { Flag } from './flags'
import { Flags } from './flags'
// const portFlag = new Flag<number>('-p', 8080)
const flags = new Flags()
const program = new Command()
program
.option('-p, --port <number>', 'server port number', '8080')
.option(
'--mongoPath <string>',
'mongo db path',
'mongodb://rushvault:rushvault@mongo:27017/',
)
.option(
'--mongoDb <string>',
'name of the databse to store collections',
'rush-vault',
)
program.parse()
const port = program.opts().port
const port = flags.getPort()
const address = `0.0.0.0:${port}`
const databaseService = new DatabaseService(
program.opts().mongoPath,
program.opts().mongoDb,
flags.getMongoDbAddress(),
flags.getMongoDbName(),
)
const characterService = new CharacterService(databaseService)
const characterService = new CharacterService(databaseService)
const app = new Server()
app.bindAsync(address, ServerCredentials.createInsecure(), () => {

32
vault/src/flags.ts Normal file
View File

@@ -0,0 +1,32 @@
import { Command } from 'commander'
export class Flags {
private readonly program = new Command()
.option('-p, --port <number>', 'server port number', '8080')
.option(
'--mongoPath <string>',
'mongo db path',
'mongodb://rushvault:rushvault@mongo:27017/',
)
.option(
'--mongoDb <string>',
'name of the databse to store collections',
'rush-vault',
)
constructor() {
this.program.parse()
}
getPort(): number {
return this.program.opts().port
}
getMongoDbAddress(): string {
return this.program.opts().mongoPath
}
getMongoDbName(): string {
return this.program.opts().mongoDb
}
}