Skip to content

Commit 66170ad

Browse files
committed
Turn existing CLI multi-command
1 parent d3f8ade commit 66170ad

File tree

1 file changed

+62
-54
lines changed
  • packages/compass-smoke-tests/src

1 file changed

+62
-54
lines changed

packages/compass-smoke-tests/src/cli.ts

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function getDefaultArch() {
5454
}
5555
}
5656

57-
const argv = yargs(hideBin(process.argv))
57+
yargs(hideBin(process.argv))
5858
.scriptName('smoke-tests')
5959
.detectLocale(false)
6060
.version(false)
@@ -67,51 +67,68 @@ const argv = yargs(hideBin(process.argv))
6767
type: 'string',
6868
default: process.env.EVERGREEN_BUCKET_KEY_PREFIX,
6969
})
70-
.option('platform', {
71-
choices: SUPPORTED_PLATFORMS,
72-
demandOption: true,
73-
default: getDefaultPlatform(),
74-
})
75-
.option('arch', {
76-
choices: SUPPORTED_ARCHS,
77-
demandOption: true,
78-
default: getDefaultArch(),
79-
})
80-
.option('package', {
81-
type: 'string',
82-
choices: SUPPORTED_PACKAGES,
83-
demandOption: true,
84-
description: 'Which package to test',
85-
})
86-
.option('forceDownload', {
87-
type: 'boolean',
88-
description: 'Force download all assets before starting',
89-
})
90-
.option('localPackage', {
91-
type: 'boolean',
92-
description: 'Use the local package instead of downloading',
93-
})
94-
.option('skipCleanup', {
95-
type: 'boolean',
96-
description: 'Do not delete the sandboxes after a run',
97-
default: false,
98-
})
99-
.option('skipUninstall', {
100-
type: 'boolean',
101-
description: 'Do not uninstall after a run',
102-
default: false,
103-
})
104-
.option('tests', {
105-
type: 'array',
106-
string: true,
107-
choices: SUPPORTED_TESTS,
108-
description: 'Which tests to run',
109-
})
110-
.default('tests', SUPPORTED_TESTS.slice());
111-
112-
async function run() {
113-
const context: SmokeTestsContext = argv.parseSync();
70+
.command(
71+
'$0',
72+
'Run smoke tests',
73+
(argv) =>
74+
argv
75+
.option('platform', {
76+
choices: SUPPORTED_PLATFORMS,
77+
demandOption: true,
78+
default: getDefaultPlatform(),
79+
})
80+
.option('arch', {
81+
choices: SUPPORTED_ARCHS,
82+
demandOption: true,
83+
default: getDefaultArch(),
84+
})
85+
.option('package', {
86+
type: 'string',
87+
choices: SUPPORTED_PACKAGES,
88+
demandOption: true,
89+
description: 'Which package to test',
90+
})
91+
.option('forceDownload', {
92+
type: 'boolean',
93+
description: 'Force download all assets before starting',
94+
})
95+
.option('localPackage', {
96+
type: 'boolean',
97+
description: 'Use the local package instead of downloading',
98+
})
99+
.option('skipCleanup', {
100+
type: 'boolean',
101+
description: 'Do not delete the sandboxes after a run',
102+
default: false,
103+
})
104+
.option('skipUninstall', {
105+
type: 'boolean',
106+
description: 'Do not uninstall after a run',
107+
default: false,
108+
})
109+
.option('tests', {
110+
type: 'array',
111+
string: true,
112+
choices: SUPPORTED_TESTS,
113+
description: 'Which tests to run',
114+
})
115+
.default('tests', SUPPORTED_TESTS.slice()),
116+
async (args) => {
117+
await run(args);
118+
}
119+
)
120+
.parseAsync()
121+
.then(
122+
() => {
123+
debug('done');
124+
},
125+
(err) => {
126+
console.error(err.stack);
127+
process.exitCode = 1;
128+
}
129+
);
114130

131+
async function run(context: SmokeTestsContext) {
115132
function cleanupMaybe() {
116133
if (context.skipCleanup) {
117134
console.log('Skipped cleanup of sandboxes');
@@ -160,12 +177,3 @@ async function run() {
160177
}
161178
}
162179
}
163-
164-
run()
165-
.then(function () {
166-
debug('done');
167-
})
168-
.catch(function (err) {
169-
console.error(err.stack);
170-
process.exitCode = 1;
171-
});

0 commit comments

Comments
 (0)