INNER CODE UNIT · Go

filterKitfile

kitops-ml/kitops · pkg/cmd/info/cmd.go:161

func filterKitfile(config *artifact.KitFile, filter string) ([]byte, error) {
	if err := checkFilterIsValid(filter); err != nil {
		return nil, fmt.Errorf("invalid filter: %w", err)
	}
	// Accept filters that start (jq-style) and don't start with a '.'; we need to trim as otherwise we start the list
	// with an empty string
	filter = strings.TrimPrefix(filter, ".")

	var filterSlice = strings.Split(filter, ".")
	value := reflect.ValueOf(config)
	for _, str := range filterSlice {
		if value.Kind() == reflect.Ptr {
			value = value.Elem()
		}
		field := value.FieldByName(cases.Title(language.Und, cases.NoLower).String(str))
		if !field.IsValid() {
			return nil, fmt.Errorf("error filtering output: cannot find required node")
		}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…