feat: much better error handling
parent
44eb07aa31
commit
d915ae20f1
|
|
@ -25,7 +25,7 @@
|
|||
"lineWidth": 120,
|
||||
"indentWidth": 2,
|
||||
"singleQuote": true,
|
||||
"proseWrap": "preserve"
|
||||
"proseWrap": "always"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
20
package.json
20
package.json
|
|
@ -24,25 +24,7 @@
|
|||
"test-i-aws": "cross-env cloudRunnerTests=true cloudRunnerCluster=aws yarn test -i -t \"cloud runner\"",
|
||||
"test-i-k8s": "cross-env cloudRunnerTests=true cloudRunnerCluster=k8s yarn test -i -t \"cloud runner\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.1",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/github": "^5.0.0",
|
||||
"@kubernetes/client-node": "^0.16.3",
|
||||
"@octokit/core": "^3.5.1",
|
||||
"async-wait-until": "^2.0.12",
|
||||
"aws-sdk": "^2.1081.0",
|
||||
"base-64": "^1.0.0",
|
||||
"commander": "^9.0.0",
|
||||
"commander-ts": "^0.2.0",
|
||||
"kubernetes-client": "^9.0.0",
|
||||
"nanoid": "^3.3.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"semver": "^7.3.5",
|
||||
"unity-changeset": "^1.6.0",
|
||||
"uuid": "^8.3.2",
|
||||
"yaml": "^1.10.2"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@arkweid/lefthook": "^0.7.7",
|
||||
"@types/jest": "^28.1.6",
|
||||
|
|
|
|||
42
src/cli.ts
42
src/cli.ts
|
|
@ -1,5 +1,4 @@
|
|||
import { yargs, YargsInstance, YargsArguments } from './dependencies.ts';
|
||||
import { default as getHomeDir } from 'https://deno.land/x/dir@1.5.1/home_dir/mod.ts';
|
||||
import { yargs, YargsInstance, YargsArguments, getHomeDir } from './dependencies.ts';
|
||||
import { engineDetection } from './middleware/engine-detection/index.ts';
|
||||
import { CommandInterface } from './command/command-interface.ts';
|
||||
import { configureLogger } from './middleware/logger-verbosity/index.ts';
|
||||
|
|
@ -99,11 +98,13 @@ export class Cli {
|
|||
|
||||
private globalOptions() {
|
||||
this.yargs
|
||||
.help('help')
|
||||
.showHelpOnFail(false, 'Specify --help for available options')
|
||||
.fail(Cli.handleFailure)
|
||||
.help(false) // Fixes broken `_handle` in yargs 17.0.0
|
||||
.version(false) // Fixes broken `_handle` in yargs 17.0.0
|
||||
.showHelpOnFail(false) // Fixes broken `_handle` in yargs 17.0.0
|
||||
.epilogue('for more information, find our manual at https://game.ci/docs/cli')
|
||||
.middleware([])
|
||||
.exitProcess(true) // prevents `_handle` from being lost
|
||||
.exitProcess(true) // Fixes broken `_handle` in yargs 17.0.0
|
||||
.strict(true);
|
||||
}
|
||||
|
||||
|
|
@ -119,22 +120,30 @@ export class Cli {
|
|||
.coerce('projectPath', async (arg) => {
|
||||
return arg.replace(/^~/, getHomeDir()).replace(/\/$/, '');
|
||||
})
|
||||
.middleware([engineDetection, vcsDetection])
|
||||
.default('engine', '')
|
||||
.default('engineVersion', '')
|
||||
.middleware([engineDetection], true)
|
||||
.default('branch', '')
|
||||
.middleware([vcsDetection], true)
|
||||
|
||||
// Todo - remove these lines with release 3.0.0
|
||||
.option('unityVersion', {
|
||||
describe: 'Override the engine version to be used',
|
||||
type: 'string',
|
||||
default: '',
|
||||
})
|
||||
.deprecateOption('unityVersion', 'This parameter will be removed. Use engineVersion instead')
|
||||
.middleware([
|
||||
async (args) => {
|
||||
if (!args.unityVersion || args.unityVersion === 'auto' || args.engine !== Engine.unity) return;
|
||||
.middleware(
|
||||
[
|
||||
async (args) => {
|
||||
if (!args.unityVersion || args.unityVersion === 'auto' || args.engine !== Engine.unity) return;
|
||||
|
||||
args.engineVersion = args.unityVersion;
|
||||
args.unityVersion = undefined;
|
||||
},
|
||||
])
|
||||
args.engineVersion = args.unityVersion;
|
||||
args.unityVersion = undefined;
|
||||
},
|
||||
],
|
||||
true,
|
||||
)
|
||||
|
||||
// End todo
|
||||
.middleware([async (args) => this.registerCommand(args, yargs)]);
|
||||
|
|
@ -154,4 +163,11 @@ export class Cli {
|
|||
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
private static handleFailure(message: string, error: Error, yargs: YargsInstance) {
|
||||
if (error) throw error;
|
||||
|
||||
log.warning(message);
|
||||
Deno.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class GameCI {
|
|||
|
||||
const success = await command.execute(options);
|
||||
|
||||
if (!success) throw new Error(`${command.name} failed.`);
|
||||
if (!success) log.warning(`${command.constructor.name} failed.`);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(error);
|
||||
|
|
|
|||
Loading…
Reference in New Issue