-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathDirToUSSDir.handler.ts
90 lines (76 loc) · 3.46 KB
/
DirToUSSDir.handler.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* 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 { AbstractSession, IHandlerParameters, TextUtils, ITaskWithStatus, TaskStage } from "@zowe/imperative";
import { IZosFilesResponse, ZosFilesAttributes, Upload, IUploadMap, IUploadOptions } from "@zowe/zos-files-for-zowe-sdk";
import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";
import * as path from "path";
/**
* Handler to upload content from a local directory to a USS directory
* @export
*/
export default class DirToUSSDirHandler extends ZosFilesBaseHandler {
public async processWithSession(commandParameters: IHandlerParameters,
session: AbstractSession): Promise<IZosFilesResponse> {
const status: ITaskWithStatus = {
statusMessage: "Uploading all files",
percentComplete: 0,
stageName: TaskStage.IN_PROGRESS
};
let inputDir: string;
// resolving to full path if local path passed is not absolute
if (path.isAbsolute(commandParameters.arguments.inputDir)) {
inputDir = commandParameters.arguments.inputDir;
} else {
inputDir = path.resolve(commandParameters.arguments.inputDir);
}
const uploadOptions: IUploadOptions = {
binary: commandParameters.arguments.binary,
maxConcurrentRequests: commandParameters.arguments.maxConcurrentRequests,
task: status,
responseTimeout: commandParameters.arguments.responseTimeout,
includeHidden: commandParameters.arguments.includeHidden,
encoding: commandParameters.arguments.encoding
};
const attributes = ZosFilesAttributes.loadFromFile(commandParameters.arguments.attributes, inputDir);
if (attributes != null) {
uploadOptions.attributes = attributes;
} else {
uploadOptions.filesMap = this.buildFilesMap(commandParameters);
}
commandParameters.response.progress.startBar({ task: status });
try {
const uploadApi = commandParameters.arguments.recursive ? Upload.dirToUSSDirRecursive : Upload.dirToUSSDir;
const response = await uploadApi.bind(Upload)(session, inputDir, commandParameters.arguments.USSDir, uploadOptions);
const formatMessage = TextUtils.prettyJson(response.apiResponse);
commandParameters.response.console.log(formatMessage);
return response;
} finally {
commandParameters.response.progress.endBar();
}
}
private buildFilesMap(commandParameters: IHandlerParameters) {
let filesMap: IUploadMap = null;
// checking if binary-files or ascii-files are used, and update filesMap argument
if (commandParameters.arguments.binaryFiles) {
filesMap = {
binary: true,
fileNames: commandParameters.arguments.binaryFiles.split(",").map((fileName: string) => fileName.trim())
};
}
if (commandParameters.arguments.asciiFiles) {
filesMap = {
binary: false,
fileNames: commandParameters.arguments.asciiFiles.split(",").map((fileName: string) => fileName.trim())
};
}
return filesMap;
}
}