-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·61 lines (57 loc) · 1.66 KB
/
cli.js
File metadata and controls
executable file
·61 lines (57 loc) · 1.66 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
#!/usr/bin/env node
import yargs from 'yargs'
import {hideBin} from 'yargs/helpers'
import {main} from './lib/main.mjs'
import {onlyParamOptions} from './lib/onlyParam.mjs'
const argv = yargs(hideBin(process.argv))
.command(
'$0 [path] [-w|--write] [--only "..."]',
`Formats all .bru files (including subdirectories)`,
yargs => {
return yargs.positional('path', {
describe: 'The root path to search from',
type: 'string',
demandOption: false,
default: '',
defaultDescription: 'Current working directory',
})
}
)
.options({
only: {
describe: 'Limit to only certain block types',
type: 'string',
choices: Object.keys(onlyParamOptions),
},
w: {
describe: 'Write mode (Formats files in place, overwriting contents)',
alias: 'write',
type: 'boolean',
default: false,
},
})
.boolean(['w', 'h'])
.alias('h', 'help')
.parse()
if (argv.h) {
yargs.showHelp()
} else {
go(argv.path, argv.w, argv.only ?? null)
}
/**
* @param {string} path
* @param {boolean} write Whether to actually modify the files or not
* @param {?string} only Limit to only the block type with a name containing value
*/
function go(path, write, only) {
main(console, process.cwd(), path, write, only)
.then(changesRequired => {
if (changesRequired) {
process.exitCode = 1
}
})
.catch(err => {
console.error(err)
process.exitCode = 1
})
}