-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDataSet.handler.ts
More file actions
54 lines (49 loc) · 2.33 KB
/
DataSet.handler.ts
File metadata and controls
54 lines (49 loc) · 2.33 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
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import type { IHandlerParameters } from "@zowe/imperative";
import type { ds, ZSshClient } from "zowe-native-proto-sdk";
import { SshBaseHandler } from "../../SshBaseHandler";
export default class CopyDataSetHandler extends SshBaseHandler {
public async processWithClient(params: IHandlerParameters, client: ZSshClient): Promise<ds.CopyDatasetResponse> {
const fromDataset = params.arguments.fromDataset;
const toDataset = params.arguments.toDataset;
const replace = params.arguments.replace ?? false;
const deleteTargetMembers = params.arguments.deleteTargetMembers ?? false;
const response = await client.ds.copyDataset({ fromDataset, toDataset, replace, deleteTargetMembers });
let dsMessage: string;
if (response.success) {
if (response.targetCreated) {
dsMessage = `Data set "${toDataset}" created and copied from "${fromDataset}"`;
} else if (deleteTargetMembers) {
dsMessage = `Target members deleted and data set "${toDataset}" replaced with contents of "${fromDataset}"`;
} else if (replace) {
dsMessage = `Data set "${toDataset}" updated with contents of "${fromDataset}"`;
} else {
dsMessage = `Data set "${fromDataset}" copied to "${toDataset}"`;
}
} else {
const r = response as ds.CopyDatasetResponse & { stderr?: string; message?: string };
const detail = r.stderr?.trim() || r.message?.trim();
dsMessage = detail
? `Copy failed: "${fromDataset}" to "${toDataset}": ${detail}`
: `Copy failed: "${fromDataset}" to "${toDataset}"`;
}
params.response.data.setMessage(dsMessage);
params.response.data.setObj(response);
if (response.success) {
params.response.console.log(dsMessage);
} else {
params.response.console.error(dsMessage);
params.response.data.setExitCode(1);
}
return response;
}
}