-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathcopy.ts
More file actions
31 lines (25 loc) · 1.08 KB
/
copy.ts
File metadata and controls
31 lines (25 loc) · 1.08 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
import * as vscode from "vscode";
import {SecretCommandArgs} from "../../treeViews/settings/secretNode";
import {VariableCommandArgs} from "../../treeViews/settings/variableNode";
type CopyCommandArgs = SecretCommandArgs | VariableCommandArgs;
type SettingType = "secret" | "variable";
type CopyPart = "name" | "value";
export function registerCopySetting(context: vscode.ExtensionContext, type: SettingType, part?: CopyPart) {
const command = part ? `github-actions.settings.${type}.copy-${part}` : `github-actions.settings.${type}.copy`;
context.subscriptions.push(
vscode.commands.registerCommand(command, async (args: CopyCommandArgs) => {
let value: string;
if (type === "secret") {
value = (args as SecretCommandArgs).secret.name;
} else {
if (part === "name") {
value = (args as VariableCommandArgs).variable.name;
} else {
value = (args as VariableCommandArgs).variable.value;
}
}
await vscode.env.clipboard.writeText(value);
vscode.window.setStatusBarMessage(`Copied ${value}`, 2000);
})
);
}