import { IHandlerParameters , TextUtils } from "@zowe/imperative" ; import { explainProvisionedInstanceExtended , explainProvisionedInstanceFull , explainProvisionedInstanceSummary , explainProvisionedInstanceSummaryWithActions , explainProvisionedInstanceSummaryWithVars , IProvisionedInstance , ListRegistryInstances , ProvisioningConstants , ListInstanceInfo } from "@zowe/provisioning-for-zowe-sdk" ; import { isNullOrUndefined } from "util" ; import { ZosmfBaseHandler } from "@zowe/zosmf-for-zowe-sdk" ; export class implements ICommandHandler export default class InstanceInfoHandler extends ZosmfBaseHandler { public async processCmd ( commandParameters ) { const registry = await ListRegistryInstances . listFilteredRegistry ( this . mSession , ProvisioningConstants . ZOSMF_VERSION , null , commandParameters . arguments . name ) ; const instances = registry [ "scr-list" ] ; if ( isNullOrUndefined ( instances ) ) { commandParameters . response . console . error ( "No instance with name " + commandParameters . arguments . name + " was found" ) ; } else if ( instances . length === 1 ) { const id = instances . pop ( ) [ "object-id" ] ; const response = await ListInstanceInfo . listInstanceCommon ( this . mSession , ProvisioningConstants . ZOSMF_VERSION , id ) ; const pretty = this . formatProvisionedInstanceSummaryOutput ( response , commandParameters . arguments . display ) ; commandParameters . response . console . log ( TextUtils . prettyJson ( pretty ) ) ; commandParameters . response . data . setObj ( response ) ; } else if ( instances . length > 1 ) { commandParameters . response . console . error ( "Multiple instances with name " + commandParameters . arguments . name + " were found" ) ; } } param { IProvisionedInstance } instance param option private formatProvisionedInstanceSummaryOutput ( instance , option ) { let prettifiedInstance = { } ; option = isNullOrUndefined ( option ) ? "ACTIONS" : option . toUpperCase ( ) ; switch ( option ) { case "EXTENDED" : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceExtended , false ) ; break ; case "SUMMARY" : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceSummary , false ) ; break ; case "VARS" : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceSummaryWithVars , false ) ; break ; case "FULL" : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceFull , false ) ; break ; case "ACTIONS" : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceSummaryWithActions , false ) ; break ; default : prettifiedInstance = TextUtils . explainObject ( instance , explainProvisionedInstanceSummaryWithActions , false ) ; break ; } return prettifiedInstance ; } }