-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add CLI #161
Closed
Closed
feat: add CLI #161
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aac1f87
feat: add CLI
remcohaszing f4a656d
Rename bin to code-cli
remcohaszing bdba426
Remove --extension-tests-path option
remcohaszing f465a5e
Use @types/pkgjs__parseargs
remcohaszing 6333a72
Revert unrelated changes
remcohaszing 32e7528
Remove lib/types.d.ts
remcohaszing a0d46b8
Merge branch 'main' into cli
remcohaszing f5eea74
Merge branch 'main' into cli
remcohaszing 8a86e22
Merge branch 'main' into cli
remcohaszing 838496d
Merge branch 'main' into cli
remcohaszing 702bae5
Merge branch 'main' into cli
remcohaszing fd8f6ac
Merge branch 'main' into cli
remcohaszing d6e8563
Merge branch 'main' into cli
remcohaszing dcbef51
Format bin.ts using Prettier
remcohaszing 28f7389
Import parseArgs from util
remcohaszing fb9f9c6
Rename --version to --vscode-version
remcohaszing 43b96f6
Add --extension-development-path to help output
remcohaszing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { resolve } from 'path'; | ||
import { parseArgs } from 'util'; | ||
import { runTests } from './runTest'; | ||
|
||
// TypeScript doesn’t allow imports outside the root dir. | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pkg = require('../package.json'); | ||
|
||
const options = { | ||
'vscode-executable-path': { type: 'string' }, | ||
'vscode-version': { type: 'string' }, | ||
platform: { type: 'string' }, | ||
'reuse-machine-install': { type: 'boolean' }, | ||
'extension-development-path': { type: 'string', multiple: true }, | ||
'launch-args': { type: 'string', multiple: true }, | ||
'extract-sync': { type: 'boolean' }, | ||
version: { type: 'boolean' }, | ||
help: { type: 'boolean' }, | ||
} as const; | ||
|
||
const versionInfo = `${pkg.name} ${pkg.version}`; | ||
|
||
const help = `Usage: code-test [options][extension-tests-path...] | ||
|
||
Options | ||
--vscode-executable-path The VS Code executable path used for testing. | ||
--vscode-version The VS Code version to download. | ||
--platform The VS Code platform to download. If not specified, it defaults to | ||
the current platform. | ||
--reuse-machine-install Whether VS Code should be launched using default settings and | ||
extensions installed on this machine. | ||
--launch-args A list of launch arguments passed to VS Code executable, | ||
--extract-sync Whether the downloaded zip should be synchronously extracted. | ||
--version Output the version information and exit. | ||
--help Show this help message. | ||
|
||
${versionInfo}`; | ||
|
||
async function main(): Promise<number> { | ||
let parsed; | ||
try { | ||
parsed = parseArgs({ options, allowPositionals: true }); | ||
} catch { | ||
console.log(help); | ||
return 1; | ||
} | ||
|
||
if (parsed.values.help) { | ||
console.log(help); | ||
return 0; | ||
} | ||
|
||
if (parsed.values.version) { | ||
console.log(versionInfo); | ||
return 0; | ||
} | ||
|
||
if (parsed.positionals.length !== 1) { | ||
console.log(help); | ||
return 1; | ||
} | ||
|
||
return runTests({ | ||
vscodeExecutablePath: parsed.values['vscode-executable-path'], | ||
version: parsed.values['vscode-version'], | ||
platform: parsed.values.platform, | ||
reuseMachineInstall: parsed.values['reuse-machine-install'], | ||
extensionDevelopmentPath: parsed.values['extension-development-path'] || process.cwd(), | ||
extensionTestsPath: resolve(process.cwd(), parsed.positionals[0]), | ||
launchArgs: parsed.values['launch-args'], | ||
extractSync: parsed.values['extract-sync'], | ||
}); | ||
} | ||
|
||
main() | ||
.catch((error) => { | ||
console.error(error); | ||
return 1; | ||
}) | ||
.then((exitCode) => { | ||
process.exitCode = exitCode; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intentionally miss this one in help? Also, is it intentionally made "multiple"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I accidentally missed that one.
It’s
multiple
, becauserunTests()
accepts it as an array.