// FilterValidTopicNameArgs filters topics from the API and returns the names
// This is used in for dynamic completion of topic names
FilterValidTopicNameArgs filters topics from the API and returns the names
This is used in for dynamic completion of topic names
// FilterValidTopicNameArgs filters topics from the API and returns the names // This is used in for dynamic completion of topic names
func FilterValidTopicNameArgs(f *factory.Factory, toComplete string) (validNames []string, directive cobra.ShellCompDirective) {
	validNames = []string{}
	directive = cobra.ShellCompDirectiveNoSpace
	svcContext, err := f.ServiceContext.Load()
	if err != nil {
		return validNames, directive
	}
	currCtx, err := contextutil.GetCurrentContext(svcContext, f.Localizer)
	if err != nil {
		return validNames, directive
	}
	instanceID := currCtx.KafkaID
	if instanceID == "" {
		return validNames, directive
	}
	conn, err := f.Connection(connection.DefaultConfigRequireMasAuth)
	if err != nil {
		return validNames, directive
	}
	api, _, err := conn.API().KafkaAdmin(instanceID)
	if err != nil {
		return validNames, directive
	}
	req := api.TopicsApi.GetTopics(f.Context)
	if toComplete != "" {
		req = req.Filter(toComplete)
	}
	topicRes, httpRes, err := req.Execute()
	if httpRes != nil {
		defer func() {
			_ = httpRes.Body.Close()
		}()
	}
	if err != nil {
		return validNames, directive
	}
	items := topicRes.GetItems()
	for _, topic := range items {
		validNames = append(validNames, topic.GetName())
	}
	return validNames, directive
}
func FilterValidTopicNameArgs ( f * factory . Factory , toComplete string ) ( validNames [ ] string , directive cobra . ShellCompDirective ) { validNames = [ ] string { } directive = cobra . ShellCompDirectiveNoSpace svcContext , err := f . ServiceContext . Load ( ) if err != nil { return validNames , directive } currCtx , err := contextutil . GetCurrentContext ( svcContext , f . Localizer ) if err != nil { return validNames , directive } instanceID := currCtx . KafkaID if instanceID == " " { return validNames , directive } conn , err := f . Connection ( connection . DefaultConfigRequireMasAuth ) if err != nil { return validNames , directive } api , _ , err := conn . API ( ) . KafkaAdmin ( instanceID ) if err != nil { return validNames , directive } req := api . TopicsApi . GetTopics ( f . Context ) if toComplete != " " { req = req . Filter ( toComplete ) } topicRes , httpRes , err := req . Execute ( ) if httpRes != nil { defer func ( ) { _ = httpRes . Body . Close ( ) } ( ) } if err != nil { return validNames , directive } items := topicRes . GetItems ( ) for _ , topic := range items { validNames = append ( validNames , topic . GetName ( ) ) } return validNames , directive }
FilterValidTopicNameArgs filters topics from the API and returns the names
This is used in for dynamic completion of topic names
FilterValidTopicNameArgs filters topics from the API and returns the names This is used in for dynamic completion of topic names