Improved CLI interface. (#145)
$ pkg-fetch -h Options: -n, --node-range [string] [default: "latest"] -p, --platform [string] [default: "linux"] -a, --arch [string] [default: "x64"] -f, --force-fetch [boolean] -b, --force-build [boolean] -v, --version Show version number [boolean] -h, --help Show help [boolean]
This commit is contained in:
parent
e314198e53
commit
ba011e4474
42
lib/bin.ts
42
lib/bin.ts
@ -1,19 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import minimist from 'minimist';
|
||||
import yargs from 'yargs';
|
||||
|
||||
import { hostPlatform, hostArch } from './system';
|
||||
import { log } from './log';
|
||||
import { need } from './index';
|
||||
import { version } from '../package.json';
|
||||
|
||||
async function main() {
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
boolean: ['f', 'b'],
|
||||
string: ['n', 'p', 'a'],
|
||||
});
|
||||
const nodeRange = argv.n || argv._.shift();
|
||||
const platform = argv.p || argv._.shift();
|
||||
const arch = argv.a || argv._.shift();
|
||||
const forceFetch = argv.f;
|
||||
const forceBuild = argv.b;
|
||||
const { argv } = yargs
|
||||
.env('PKG_FETCH_OPTION_')
|
||||
.option('node-range', { alias: 'n', default: 'latest', type: 'string' })
|
||||
.option('platform', { alias: 'p', default: hostPlatform, type: 'string' })
|
||||
.option('arch', { alias: 'a', default: hostArch, type: 'string' })
|
||||
.option('force-fetch', {
|
||||
alias: 'f',
|
||||
type: 'boolean',
|
||||
})
|
||||
.option('force-build', {
|
||||
alias: 'b',
|
||||
type: 'boolean',
|
||||
})
|
||||
.conflicts('force-fetch', 'force-build')
|
||||
.version(version)
|
||||
.alias('v', 'version')
|
||||
.help()
|
||||
.alias('h', 'help');
|
||||
|
||||
const {
|
||||
'node-range': nodeRange,
|
||||
platform,
|
||||
arch,
|
||||
'force-fetch': forceFetch,
|
||||
'force-build': forceBuild,
|
||||
} = argv;
|
||||
|
||||
const local = await need({
|
||||
nodeRange,
|
||||
platform,
|
||||
@ -21,6 +42,7 @@ async function main() {
|
||||
forceFetch,
|
||||
forceBuild,
|
||||
});
|
||||
|
||||
log.info(local);
|
||||
}
|
||||
|
||||
|
||||
@ -131,6 +131,9 @@ export async function need(opts: NeedOptions) {
|
||||
|
||||
if (!dryRun && fetchFailed) {
|
||||
log.info('Not found in remote cache:', JSON.stringify(remote));
|
||||
if (forceFetch) {
|
||||
throw wasReported(`Failed to fetch.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dryRun) {
|
||||
|
||||
@ -36,12 +36,12 @@
|
||||
"expand-template": "^2.0.3",
|
||||
"fs-extra": "^9.1.0",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"minimist": "^1.2.5",
|
||||
"progress": "^2.0.3",
|
||||
"request": "^2.88.2",
|
||||
"request-progress": "^3.0.0",
|
||||
"semver": "^7.3.5",
|
||||
"unique-temp-dir": "^1.0.0"
|
||||
"unique-temp-dir": "^1.0.0",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.13.10",
|
||||
@ -56,11 +56,11 @@
|
||||
"@types/byline": "^4.2.32",
|
||||
"@types/fs-extra": "^9.0.9",
|
||||
"@types/isomorphic-fetch": "^0.0.35",
|
||||
"@types/minimist": "^1.2.1",
|
||||
"@types/node": "^14.14.37",
|
||||
"@types/progress": "^2.0.3",
|
||||
"@types/request": "^2.48.5",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@types/yargs": "^16.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.19.0",
|
||||
"@typescript-eslint/parser": "^4.19.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user