-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateGroups
More file actions
48 lines (39 loc) · 1.25 KB
/
createGroups
File metadata and controls
48 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const path = require('path');
const { program, InvalidArgumentError } = require('commander');
const groupsGenerator = require('./src/groupGenerator');
function myParseInt(value) {
const parsedValue = parseInt(value, 10);
// eslint-disable-next-line no-restricted-globals
if (isNaN(parsedValue) || value === true) {
throw new InvalidArgumentError('Not a number');
}
return parsedValue;
}
program
.name('Random Group Generator')
.description('This script creates a random groups from a list of names, can be seeded')
.version('1.0.0');
program
.argument('<filepath>', 'input filepath containing list of names')
.option('-g, --groups <number>', 'number of groups', myParseInt, 2)
.option('-o, --output <filepath>', 'output filepath', './output.txt')
.option('-s, --seed <string>', 'Seed for the randomizer', undefined)
.action((filepath, options) => {
const {
groups,
seed,
output,
} = options;
const inputPath = path.join(__dirname, filepath);
const outputPath = path.join(__dirname, output);
groupsGenerator({
inputPath,
outputPath,
groupsNumber: groups,
seed,
});
});
program.addHelpText('after', `
Example call:
$ node createGroups ./input.txt -g 28`);
program.parse();