Repository navigation
Expand file tree
/
Copy pathyargs.ts
More file actions
283 lines (276 loc) · 7.43 KB
/
Copy pathyargs.ts
File metadata and controls
283 lines (276 loc) · 7.43 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import * as yargs from "yargs";
import { StyleType, SummaryType, LineMatchingType, FormatType, InputType, OutputType, DiffyType, CoverageReporterType, DisplayMode } from "./types";
export interface Argv {
style: StyleType;
synchronisedScroll: boolean;
summary: SummaryType;
matching: LineMatchingType;
matchWordsThreshold: number;
matchingMaxComparisons: number;
format: FormatType;
input: InputType;
output: OutputType;
diffy?: DiffyType;
file?: string;
htmlWrapperTemplate?: string;
ignore?: string[];
extraArguments: string[];
coverage: string;
coverageFilePatterns: string;
workspace: string;
coverageReporter: string;
customFileNameGeneratorFile: string;
displayMode: string;
strict: boolean;
saveDebug: boolean;
caseInsensitive: boolean;
}
export function setup(): Argv {
const currentYear = new Date().getFullYear();
const styleChoices: StyleType[] = ["line", "side"];
const summaryChoices: SummaryType[] = ["closed", "open", "hidden"];
const matchingChoices: LineMatchingType[] = ["lines", "words", "none"];
const formatChoices: FormatType[] = ["html", "json"];
const inputChoices: InputType[] = ["file", "command", "stdin"];
const outputChoices: OutputType[] = ["preview", "stdout"];
const diffyChoices: DiffyType[] = ["browser", "pbcopy", "print"];
const coverageReporterChoices: CoverageReporterType[] = ["auto", "json", "cobertura", "jacoco", "xccov"];
const displayModeChoices: DisplayMode[] = ["standard", "simplify"];
const argv = yargs
.usage("Usage: diff2html [options] -- [diff args]")
.options({
style: {
alias: "s",
describe: "Output style",
nargs: 1,
type: "string",
choices: styleChoices,
default: "line"
}
})
.options({
synchronisedScroll: {
alias: "sc",
describe: "Synchronised horizontal scroll",
type: "boolean",
default: true
}
})
.options({
summary: {
alias: "su",
describe: "Show files summary",
type: "string",
choices: summaryChoices,
default: "closed"
}
})
.options({
matching: {
alias: "lm",
describe: "Diff line matching type",
nargs: 1,
type: "string",
choices: matchingChoices,
default: "none"
}
})
.options({
matchWordsThreshold: {
alias: "lmt",
describe: "Diff line matching word threshold",
nargs: 1,
type: "number",
default: 0.25
}
})
.options({
matchingMaxComparisons: {
alias: "lmm",
describe: "Diff line matching maximum line comparisons of a block of changes",
nargs: 1,
type: "number",
default: 1000
}
})
.options({
format: {
alias: "f",
describe: "Output format",
nargs: 1,
type: "string",
choices: formatChoices,
default: "html"
}
})
.options({
input: {
alias: "i",
describe: "Diff input source",
nargs: 1,
type: "string",
choices: inputChoices,
default: "command"
}
})
.options({
output: {
alias: "o",
describe: "Output destination",
nargs: 1,
type: "string",
choices: outputChoices,
default: "preview"
}
})
.options({
diffy: {
alias: "u",
describe: "Upload to diffy.org",
nargs: 1,
type: "string",
choices: diffyChoices
}
})
.options({
file: {
alias: "F",
describe: "Send output to file (overrides output option)",
nargs: 1,
type: "string"
}
})
.options({
htmlWrapperTemplate: {
alias: "hwt",
describe: "Use a custom template when generating markup",
nargs: 1,
type: "string"
}
})
.options({
ignore: {
alias: "ig",
describe: "ignore a file",
nargs: 1,
type: "array"
}
})
.options({
coverage: {
alias: "c",
describe: "Coverage JSON file",
nargs: 1,
type: "string",
}
})
.options({
coverageFilePatterns: {
alias: "p",
describe: "Coverage files patterns",
nargs: 1,
type: "string",
}
})
.options({
workspace: {
alias: "ws",
describe: "Workspace of project",
nargs: 1,
type: "string",
}
})
.options({
coverageReporter: {
alias: "cr",
describe: "Coverage reporter type of coverage file",
nargs: 1,
type: "string",
choices: coverageReporterChoices,
default: "auto"
}
})
.options({
customFileNameGeneratorFile: {
alias: "cfng",
describe: "Generate file name by rules to match file name in coverage",
nargs: 1,
type: "string",
}
})
.options({
displayMode: {
alias: "dm",
describe: "Display mode",
nargs: 1,
choices: displayModeChoices,
}
})
.options({
strict: {
alias: "strict",
describe: "Strict mode",
type: "boolean",
default: false
}
})
.options({
saveDebug: {
alias: "saveDebug",
describe: "Save debug data, git diff and coverage file will be saved",
type: "boolean",
default: false
}
})
.options({
caseInsensitive: {
alias: "caseInsensitive",
describe: "coverage file path case insensitive",
type: "boolean",
default: false
}
})
.example(
"diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1",
"diff last commit, line by line, word comparison between lines," +
"previewed in the browser and input from git diff command"
)
.example("diff2html -i file -- my-file-diff.diff", "reading the input from a file")
.example("diff2html -f json -o stdout -- -M HEAD~1", "print json format to stdout")
.example("diff2html -F my-pretty-diff.html -- -M HEAD~1", "print to file")
.example("diff2html --ig package-lock.json --ig yarn.lock", "ignore two particular files when generating the diff")
.help("h")
.alias("v", "version")
.alias("h", "help")
.epilog(
`© 2014-${currentYear} rtfpessoa
For more information, check out https://diff2html.xyz/
For support, check out https://github.com/rtfpessoa/diff2html-cli`
)
.strict(true)
.recommendCommands().argv;
// HACK: Forcing conversions to better types here, since choices types are enforced in the beggining
return {
...argv,
style: argv.style as StyleType,
summary: argv.summary as SummaryType,
matching: argv.matching as LineMatchingType,
format: argv.format as FormatType,
input: argv.input as InputType,
output: argv.output as OutputType,
diffy: argv.diffy as DiffyType,
ignore: (argv.ignore || []).map((e) => e.toString()),
extraArguments: argv._ || [],
coverage: argv.coverage as string,
coverageFilePatterns: argv.coverageFilePatterns as string,
workspace: argv.workspace as string,
coverageReporter: argv.coverageReporter as string,
customFileNameGeneratorFile: argv.customFileNameGeneratorFile as string,
displayMode: argv.displayMode as string,
strict: argv.strict as boolean,
saveDebug: argv.saveDebug as boolean
};
}
export function help(): void {
yargs.showHelp("log");
}