-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathunshare.ts
More file actions
76 lines (67 loc) · 2.39 KB
/
unshare.ts
File metadata and controls
76 lines (67 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { TfCommand } from "../../lib/tfcommand";
import args = require("../../lib/arguments");
import extBase = require("./default");
import extInfo = require("./_lib/extensioninfo");
import trace = require("../../lib/trace");
export function getCommand(args: string[]): TfCommand<extBase.ExtensionArguments, string[]> {
// this just offers description for help and to offer sub commands
return new ExtensionShare(args);
}
export class ExtensionShare extends extBase.ExtensionBase<string[]> {
protected description = "Unshare a Azure Devops Extension with Azure DevOps Organizations.";
protected serverCommand = true;
constructor(passedArgs: string[]) {
super(passedArgs);
// Override this argument so we are prompted (e.g. no default provided)
this.registerCommandArgument(
"unshareWith",
"Un-share with",
"List of organizations with which to un-share the extension",
args.ArrayArgument,
);
this.registerCommandArgument(
"serviceUrl",
"Market URL",
"URL to the VSS Marketplace.",
args.StringArgument,
extBase.ExtensionBase.getMarketplaceUrl,
);
}
protected getHelpArgs(): string[] {
return ["publisher", "extensionId", "vsix", "unshareWith"];
}
public async exec(): Promise<string[]> {
const galleryApi = await this.webApi.getGalleryApi(this.webApi.serverUrl);
return this.commandArgs.vsix.val(true).then(vsixPath => {
let extInfoPromise: Promise<extInfo.CoreExtInfo>;
if (vsixPath !== null) {
extInfoPromise = extInfo.getExtInfo(vsixPath[0], null, null);
} else {
extInfoPromise = Promise.all([this.commandArgs.publisher.val(), this.commandArgs.extensionId.val()]).then<
extInfo.CoreExtInfo
>(values => {
const [publisher, extension] = values;
return extInfo.getExtInfo(null, extension, publisher);
});
}
return extInfoPromise.then(extInfo => {
return this.commandArgs.unshareWith.val().then(unshareWith => {
let sharePromises: Promise<void>[] = [];
unshareWith.forEach(account => {
sharePromises.push(galleryApi.unshareExtension(extInfo.publisher, extInfo.id, account));
});
return Promise.all(sharePromises).then(() => {
return unshareWith;
});
});
});
});
}
protected friendlyOutput(data: string[]): void {
trace.success("\n=== Completed operation: un-share extension ===");
trace.info(" - Removed sharing from:");
data.forEach(acct => {
trace.info(" - " + acct);
});
}
}