-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotondb-cli.js
executable file
·72 lines (66 loc) · 2.27 KB
/
protondb-cli.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
#!/usr/bin/env node
import yargs from 'yargs/yargs'
import { hideBin } from 'yargs/helpers'
import start from './lib/process/index.js'
import { isValidGameName } from './lib/utils.js'
import chalk from 'chalk'
import getConfig from './lib/config/index.js'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import os from 'os'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const pkg = path.join(__dirname, 'package.json')
const info = JSON.parse(fs.readFileSync(pkg, 'utf8'))
const config = getConfig()
const DEFAULT_PROTONDB_CLI_CONCURRENCY = os.cpus().length
const argv = hideBin(process.argv)
const protondbCLI = yargs(argv)
.scriptName('protondb-cli')
.version(info.version)
.usage('$0 [game]', 'Search for games based on a key word and show their protondb compatability, score and any other information related', (yargs) => {
yargs.positional('game', {
describe: 'Game\'s name.',
type: 'string',
default: null,
normalize: true,
coerce: isValidGameName
}).option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging'
}).option('hits', {
alias: 'h',
type: 'number',
description: 'Limit the number of result on the search',
default: config.DEFAULT_PROTONDB_CLI_HITS
}).option('concurrency', {
alias: 'c',
type: 'number',
description: 'Limit the concurrency for the search',
default: DEFAULT_PROTONDB_CLI_CONCURRENCY
}).option('disable_cache', {
alias: 'dc',
type: 'boolean',
description: 'Force protondb-cli not to use the cache',
default: false
}).option('clear_cache', {
alias: 'cc',
type: 'boolean',
description: 'Clean up the local cache',
default: false
})
.example([
['$0 gta --concurrency 5 --hits 15', 'Search the last 15 like gta using a conccurency of 5']
]).fail(function (msg, err, yargs) {
if (err instanceof Error && (argv.includes('-v') || argv.includes('--verbose'))) {
console.error(err)
}
const errorStyle = chalk.bold.red
console.error(errorStyle(msg))
console.log(yargs.help())
process.exit(1)
})
}).argv
start(protondbCLI)