Files
blitzkit/src/core/process/args.ts
T

28 lines
712 B
TypeScript
Raw Normal View History

2023-04-28 13:42:42 +00:00
import { argv } from 'process';
2023-06-06 16:50:33 +00:00
import errorWithCause from './errorWithCause.js';
2023-04-28 13:42:42 +00:00
type ArgumentName = 'discord-token' | 'wargaming-application-id';
const args: Record<ArgumentName, string> = {
2023-04-28 13:42:42 +00:00
'discord-token': '',
'wargaming-application-id': '',
};
argv.forEach((arg) => {
if (arg.includes('=')) {
const [name, value] = arg.split('=');
args[name as ArgumentName] = value;
}
});
Object.keys(args).forEach((arg) => {
if (args[arg as ArgumentName] === '') {
2023-06-06 16:50:33 +00:00
throw errorWithCause(
`Missing argument: ${arg}`,
'Missing required auth key.',
);
2023-04-28 13:42:42 +00:00
}
});
export const discordToken = args['discord-token'];
export const wargamingApplicationId = args['wargaming-application-id'];