--install-extension #691

This commit is contained in:
Joao Moreno
2016-05-04 17:25:16 +02:00
parent eab9ef45a4
commit 6043ff88dc
3 changed files with 47 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { ParsedArgs } from 'vs/code/node/argv';
import { TPromise } from 'vs/base/common/winjs.base';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
@@ -23,6 +24,9 @@ import { NodeRequestService } from 'vs/platform/request/node/nodeRequestService'
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { NodeConfigurationService } from 'vs/platform/configuration/node/nodeConfigurationService';
const notFound = id => localize('notFound', "Extension '{0}' not found.", id);
const useId = localize('useId', "Make sure you use the full extension id, eg: {0}", 'ms-vscode.csharp');
class Main {
constructor(
@@ -31,12 +35,48 @@ class Main {
) {}
run(argv: ParsedArgs): TPromise<any> {
// TODO@joao - make this contributable
if (argv['list-extensions']) {
return this.extensionManagementService.getInstalled().then(extensions => {
extensions.forEach(e => console.log(`${ e.displayName } (${ getExtensionId(e) })`));
});
return this.listExtensions();
} else if (argv['install-extension']) {
return this.installExtension(argv['install-extension']);
}
}
private listExtensions(): TPromise<any> {
return this.extensionManagementService.getInstalled().then(extensions => {
extensions.forEach(e => console.log(`${ e.displayName } (${ getExtensionId(e) })`));
});
}
private installExtension(id: string): TPromise<any> {
return this.extensionGalleryService.query({ ids: [id] }).then(result => {
const [extension] = result.firstPage;
if (!extension) {
return TPromise.wrapError(`${ notFound(id) }\n${ useId }`);
}
return this.extensionManagementService.getInstalled().then(installed => {
const isInstalled = installed.some(e => getExtensionId(e) === id);
if (isInstalled) {
return TPromise.wrapError(localize('alreadyInstalled', "Extension '{0}' is already installed.", id));
}
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
console.log(localize('installing', "Installing..."));
return this.extensionManagementService.install(extension).then(extension => {
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!",
getExtensionId(extension),
extension.version
));
});
});
});
}
}
export function main(argv: ParsedArgs): TPromise<void> {