import { AbstractSession , IHandlerParameters , ITaskWithStatus , TaskStage , TextUtils } from "@zowe/imperative" ; import { IZosFilesResponse , Upload , IUploadResult } from "@zowe/zos-files-for-zowe-sdk" ; import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler" ; export export default class FileToDataSetHandler extends ZosFilesBaseHandler { public async processWithSession ( commandParameters , session ) { const task = { percentComplete : 0 , statusMessage : "Uploading to data set" , stageName : TaskStage . IN_PROGRESS } ; commandParameters . response . progress . startBar ( { task } ) ; const response = await Upload . fileToDataset ( session , commandParameters . arguments . inputfile , commandParameters . arguments . dataSetName , { volume : commandParameters . arguments . volumeSerial , binary : commandParameters . arguments . binary , encoding : commandParameters . arguments . encoding , task , responseTimeout : commandParameters . arguments . responseTimeout } ) ; if ( response . apiResponse ) { let skipCount = 0 ; let successCount = 0 ; let errorCount = 0 ; response . apiResponse . forEach ( ( element ) => { if ( element . success === true ) { const formatMessage = TextUtils . prettyJson ( element ) ; commandParameters . response . console . log ( formatMessage ) ; successCount ++ ; } else if ( element . success === false ) { const formatMessage = TextUtils . prettyJson ( element ) ; commandParameters . response . console . error ( TextUtils . chalk . red ( formatMessage ) ) ; errorCount ++ ; } else { skipCount ++ ; } } ) ; commandParameters . response . console . log ( TextUtils . prettyJson ( { file_to_upload : response . apiResponse . length , success : successCount , error : errorCount , skipped : skipCount } ) ) ; } return response ; } }