-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dff323
commit e504a6c
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import config from '@kaetram/common/config'; | ||
|
||
/** | ||
* Class responsible for overriding the default arguments. | ||
*/ | ||
|
||
export default class Args { | ||
public constructor(private params: string[] = process.argv) { | ||
if (params.length < 2) return; | ||
|
||
// Iterate through the additional parameters and override the default values. | ||
for (let i = 2; i < this.params.length; i += 2) { | ||
let paramIdentifier = this.params[i], | ||
paramValue = this.params[i + 1]; | ||
|
||
this.override(paramIdentifier, paramValue); | ||
} | ||
} | ||
|
||
/** | ||
* Takes a parameter key and overrides the environment variables in the | ||
* configuration based on that. | ||
* @param key The key of the parameter. | ||
* @param value The value of the parameter. | ||
*/ | ||
|
||
private override(key: string, value: string): void { | ||
switch (key) { | ||
case '--host': { | ||
config.host = value; | ||
break; | ||
} | ||
|
||
case '--port': { | ||
config.port = parseInt(value); | ||
config.apiPort = parseInt(value) + 1; | ||
break; | ||
} | ||
|
||
case 'remoteServerHost': { | ||
config.remoteServerHost = value; | ||
break; | ||
} | ||
|
||
case 'serverId': { | ||
config.serverId = parseInt(value); | ||
break; | ||
} | ||
|
||
case 'updateTime': { | ||
config.updateTime = parseInt(value); | ||
break; | ||
} | ||
|
||
case 'maxPlayers': { | ||
config.maxPlayers = parseInt(value); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters