add commander for cli flags
This commit is contained in:
10
vault/package-lock.json
generated
10
vault/package-lock.json
generated
@@ -13,6 +13,7 @@
|
||||
"@grpc/proto-loader": "^0.7.15",
|
||||
"@grpc/reflection": "^1.0.4",
|
||||
"@protobuf-ts/protoc": "^2.11.0",
|
||||
"commander": "^14.0.0",
|
||||
"express": "^5.1.0",
|
||||
"google-protobuf": "^3.21.4",
|
||||
"mongodb": "^6.17.0"
|
||||
@@ -1329,6 +1330,15 @@
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "14.0.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz",
|
||||
"integrity": "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"@grpc/proto-loader": "^0.7.15",
|
||||
"@grpc/reflection": "^1.0.4",
|
||||
"@protobuf-ts/protoc": "^2.11.0",
|
||||
"commander": "^14.0.0",
|
||||
"express": "^5.1.0",
|
||||
"google-protobuf": "^3.21.4",
|
||||
"mongodb": "^6.17.0"
|
||||
|
||||
@@ -3,17 +3,41 @@ import { MongoClient } from 'mongodb'
|
||||
|
||||
import { CharacterService } from './character_service'
|
||||
import { DatabaseService } from './database'
|
||||
import { Command } from 'commander'
|
||||
// import { Flag } from './flags'
|
||||
|
||||
// const portFlag = new Flag<number>('-p', 8080)
|
||||
|
||||
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 = 8080
|
||||
const address = `0.0.0.0:${port}`
|
||||
|
||||
const databaseService = new DatabaseService(
|
||||
program.opts().mongoPath,
|
||||
program.opts().mongoDb,
|
||||
)
|
||||
const characterService = new CharacterService(databaseService)
|
||||
|
||||
const app = new Server()
|
||||
|
||||
const databaseService = new DatabaseService('mongodb://rushvault:rushvault@mongo:27017/', 'rush-vault')
|
||||
const characterService = new CharacterService(databaseService)
|
||||
|
||||
characterService.addToServer(app)
|
||||
|
||||
app.bindAsync(address, ServerCredentials.createInsecure(), () => {
|
||||
characterService.addToServer(app)
|
||||
console.log(`Starting server at ${address}`)
|
||||
})
|
||||
|
||||
@@ -20,10 +20,6 @@ export class CharacterService {
|
||||
characterManager: ICharacterManager
|
||||
databaseService: DatabaseService
|
||||
|
||||
// mongoClient: MongoClient
|
||||
// db: Db
|
||||
// characterCollection: Collection
|
||||
|
||||
constructor(databaseService: DatabaseService) {
|
||||
this.reflectionService = new ReflectionService(
|
||||
loadSync('./src/proto/character.proto'),
|
||||
@@ -35,10 +31,6 @@ export class CharacterService {
|
||||
}
|
||||
|
||||
this.databaseService = databaseService
|
||||
|
||||
// this.mongoClient = mongoClient
|
||||
// this.db = this.mongoClient.db(dbName)
|
||||
// this.characterCollection = this.db.collection('Characters')
|
||||
}
|
||||
|
||||
addToServer(server: Server) {
|
||||
@@ -51,17 +43,9 @@ export class CharacterService {
|
||||
call: ServerUnaryCall<CreateCharacterRequest, Character>,
|
||||
callback: sendUnaryData<Character>,
|
||||
) {
|
||||
|
||||
let newCharacter = await this.databaseService.insertCharacter(call.request.characterData)
|
||||
|
||||
// this.characterCollection
|
||||
// .insertOne(call.request.characterData)
|
||||
// .then((insertResult) => {
|
||||
// console.log(insertResult)
|
||||
// return this.characterCollection.findOne({
|
||||
// _id: insertResult.insertedId,
|
||||
// })
|
||||
// })
|
||||
let newCharacter = await this.databaseService.insertCharacter(
|
||||
call.request.characterData,
|
||||
)
|
||||
|
||||
console.log(newCharacter)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user