-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (82 loc) · 2.26 KB
/
index.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
import yargs from 'yargs/yargs';
import Play from './lib/play.js';
import Roller from './lib/roll.js';
yargs()
.scriptName('roller')
.usage('$0 <notation..> [options]')
.example('$0 4d6', 'roll a 6 sided die 4 times')
.example('$0 2d10+7', 'roll a 10 sided die 2 times and add 7')
.example('$0 play', 'start the interactive CLI dice game')
.command({
command: '$0 <notation..>',
aliases: ['roll'],
desc: 'roll the dice',
builder: (yargs) => {
yargs.positional('notation', {
type: 'string',
describe: 'space separated list of notation to roll',
});
yargs
.options({
's': {
alias: 'separator',
demandOption: false,
default: '; ',
describe: 'String to separate dice rolls',
type: 'string',
},
'e': {
alias: 'engine',
demandOption: false,
describe: 'The RNG engine to use',
type: 'string',
},
'seed': {
demandOption: false,
describe: 'The RNG engine seed',
type: 'number',
},
'f': {
alias: 'format',
demandOption: false,
describe: 'The output format',
type: 'string',
default: 'string',
},
'result-only': {
demandOption: false,
description: 'Only return the roll result, without the notation or dice rolled',
type: 'boolean',
default: false,
},
})
},
handler: Roller,
})
.command({
command: 'play',
desc: 'play an interactive CLI dice game',
builder: (yargs) => {
yargs
.options({
'players': {
describe: 'The name of a player',
type: 'array',
},
count: {
describe: 'The number of players',
type: 'number',
},
})
.epilog('For more information visit https://dice-roller.github.io/documentation');
},
handler: Play,
})
.demandCommand()
.epilog('For more information visit https://dice-roller.github.io/documentation')
.help()
.alias('version', 'V')
.strict()
//.argv;
.parse(process.argv.slice(2));