-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexecution_options.ts
67 lines (63 loc) · 1.96 KB
/
execution_options.ts
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
import yargs from 'yargs'
import type { ExecutionOptions } from '~src/interface'
export class ExecutionOptionsImpl implements ExecutionOptions {
public debug!: boolean
public console!: boolean
public output!: string
public inputDir!: string
public exercise!: string
public dry!: boolean
public noTemplates!: boolean
public pretty!: boolean
constructor(options: ExecutionOptions) {
Object.assign(this, options)
}
public static create(): ExecutionOptions {
const args = yargs
.usage('Usage: $0 <exercise> <input-directory> [options]')
.example(
'$0 two-fer ~/javascript/two-fer/128/',
'Analyze the input directory "128" against the two-fer analyzer'
)
.alias('d', 'debug')
.alias('c', 'console')
.alias('o', 'output')
.alias('p', 'pretty')
.describe('d', 'Unless given, only outputs warnings and errors')
.describe('c', 'If given, outputs to the console')
.describe(
'o',
'Path relative to the input dir where the analyzis results are stored'
)
.describe(
'noTemplates',
'Unless given, exports templates instead of messages (feature flag)'
)
.describe(
'p',
'If given, formats the JSON output using 2 space indentation'
)
.describe('dry', 'If given, does not output anything to disk')
.boolean(['d', 'c', 'p', 'dry', 'noTemplates'])
.string('o')
.default('d', process.env.NODE_ENV === 'development')
.default('c', process.env.NODE_ENV === 'development')
.default('noTemplates', false)
.default('p', false)
.default('o', './analysis.json')
.default('dry', false)
.help('h')
.alias('h', 'help').argv
const { d, c, o, dry, p, noTemplates, _ } = args
return new ExecutionOptionsImpl({
debug: d,
console: c,
output: o,
pretty: p,
dry,
noTemplates,
exercise: String(_[0]),
inputDir: String(_[1]),
})
}
}