import { IHandlerParameters , TextUtils } from "@zowe/imperative" ; import { explainProvisionedInstanceFull , explainProvisionedInstanceSummary , IProvisionedInstance , IProvisionedInstances , ProvisioningConstants , ListRegistryInstances } 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 RegistryInstancesHandler extends ZosmfBaseHandler { public async processCmd ( commandParameters ) { const response = await ListRegistryInstances . listFilteredRegistry ( this . mSession , ProvisioningConstants . ZOSMF_VERSION , commandParameters . arguments . filterByType , commandParameters . arguments . filterByExternalName ) ; const instances = response [ "scr-list" ] ; const pretty = TextUtils . prettyJson ( this . formatProvisionedInstancesSummaryOutput ( instances , commandParameters . arguments . allInfo ) ) ; if ( commandParameters . arguments . types ) { commandParameters . response . console . log ( "z/OSMF Service Registry " + "- Types of Provisioned Instances.\n" ) ; const unique = [ ... new Set ( instances . map ( ( item ) => item . type ) ) ] ; commandParameters . response . console . log ( TextUtils . prettyJson ( unique ) ) ; } else { commandParameters . response . console . log ( "z/OSMF Service Registry" ) ; if ( ! isNullOrUndefined ( commandParameters . arguments . filterByType ) ) { commandParameters . response . console . log ( "\nShowing ONLY \"" + commandParameters . arguments . filterByType . toUpperCase ( ) + "\" instance types." ) ; } commandParameters . response . console . log ( pretty ) ; } commandParameters . response . data . setObj ( response ) ; } param { IProvisionedInstance } instances param showAllInfo private formatProvisionedInstancesSummaryOutput ( instances , showAllInfo ) { let prettifiedInstances = [ ] ; if ( showAllInfo ) { prettifiedInstances = TextUtils . explainObject ( instances , explainProvisionedInstanceFull , true ) ; } else { prettifiedInstances = TextUtils . explainObject ( instances , explainProvisionedInstanceSummary , false ) ; } return prettifiedInstances ; } }