import { Arguments , KResponse , Registrar , MultiModalResponse , NavResponse } from '@kui-shell/core' ; import { doHelp , KubeOptions } from '@kui-shell/plugin-kubectl' ; import isUsage from './usage' ; import doExecWithStdout from './exec' ; import apiVersion from './apiVersion' ; import { HelmRelease } from '../../models/release' ; async function doGet ( args ) { if ( isUsage ( args , 'get' ) ) { return doHelp ( 'helm' , args ) ; } const { argvNoOptions } = args ; const projIdx = argvNoOptions . indexOf ( 'get' ) + 1 ; const releaseIdx = argvNoOptions . length - 1 ; const projection = projIdx < releaseIdx ? argvNoOptions [ projIdx ] : undefined ; const releaseName = argvNoOptions [ releaseIdx ] ; const basic = /REVISION:\s+(\S+)[\n\r]+RELEASED:\s+([^\n\r]+)[\n\r]+CHART:\s+(\S+)/ ; const response = await doExecWithStdout ( args ) ; if ( projection ) { return response ; } const match = response . match ( basic ) ; if ( ! match ) { return response ; } const revision = match [ 1 ] ; const creationTimestamp = match [ 2 ] ; const endOfBasicSection = Math . min ( response . indexOf ( 'USER-SUPPLIED VALUES' ) , response . indexOf ( 'COMPUTED VALUES' ) ) ; return { apiVersion , kind : 'HelmRelease' , metadata : { name : releaseName , generation : revision , creationTimestamp } , summary : { content : response . substring ( 0 , endOfBasicSection ) . trim ( ) , contentType : 'yaml' } , isSimulacrum : true , originatingCommand : args , isKubeResource : true , kuiRawData : response , modes : [ ] } ; } export default ( registrar ) => { registrar . listen ( '/helm/get' , doGet ) ; } ;