func parseSelector(s ...string) (string, error) {
	selector := DefaultSelector
	switch len(s) {
	case 0:
		break
	case 1:
		selector = s[0]
	default:
		return "", fmt.Errorf("expected max 1 argument, got %d", len(s))
	}
	return selector, nil
}
Parse template tag with max 1 argument - selector
package main
import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	gotemplate "text/template"
	"strings"
	"github.com/Masterminds/sprig/v3"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
	DefaultNamespace = metav1.NamespaceDefault
	DefaultSelector  = ""
)
type Template struct {
	desc *TemplateDescriptor
	name string
	template *gotemplate.Template
	lastOutput string
}
func newTemplate(cfg *Config, dm *DependencyManager, d *TemplateDescriptor) (*Template, error) {
	name := filepath.Base(d.Path)
	o, err := ioutil.ReadFile(d.Output)
	if err != nil {
		o = nil
	}
	data, err := ioutil.ReadFile(d.Path)
	if err != nil {
		return nil, err
	}
	s := string(data)
	template, err := gotemplate.New(name).Delims(cfg.LeftDelimiter, cfg.RightDelimiter).Funcs(funcMap(dm)).Parse(s)
	if err != nil {
		return nil, err
	}
	return &Template{
		desc:       d,
		name:       name,
		template:   template,
		lastOutput: string(o),
	}, nil
}
func newTemplatesFromConfig(cfg *Config, dm *DependencyManager) ([]*Template, error) {
	templates := make([]*Template, 0, len(cfg.TemplateDescriptors))
	for _, d := range cfg.TemplateDescriptors {
		t, err := newTemplate(cfg, dm, d)
		if err != nil {
			return nil, err
		}
		templates = append(templates, t)
	}
	return templates, nil
}
func (t *Template) Process(dryRun bool) (bool, error) {
	if r, err := t.Render(); err == nil {
		if changed := !(r == t.lastOutput); changed {
			if !dryRun {
				if err := t.Write([]byte(r)); err != nil {
					return false, err
				}
			}
			t.lastOutput = r
			return true, nil
		}
		return false, nil
	} else {
		return false, err
	}
}
func (t *Template) Write(content []byte) error {
	dir := filepath.Dir(t.desc.Output)
	if _, err := os.Stat(t.desc.Output); os.IsNotExist(err) {
		if err := os.MkdirAll(dir, 0755); err != nil {
			return err
		}
		if err := ioutil.WriteFile(t.desc.Output, content, 0644); err != nil {
			return err
		}
	} else {
		var f *os.File
		if f, err = ioutil.TempFile(dir, t.name); err != nil {
			return err
		}
		defer UnlinkQuietly(f.Name())
		if _, err := f.Write(content); err != nil {
			return err
		}
		if err := f.Sync(); err != nil {
			return err
		}
		if err := f.Close(); err != nil {
			return err
		}
		if err := os.Chmod(f.Name(), 0644); err != nil {
			return err
		}
		if err := os.Rename(f.Name(), t.desc.Output); err != nil {
			return err
		}
	}
	return nil
}
func (t *Template) Render() (string, error) {
	buf := new(bytes.Buffer)
	if err := t.template.Execute(buf, nil); err != nil {
		return "", err
	}
	return buf.String(), nil
}
func funcMap(dm *DependencyManager) gotemplate.FuncMap {
	f := gotemplate.FuncMap{
		"toLower":   strings.ToLower,
		"toUpper":   strings.ToUpper,
		"toTitle":   strings.Title,
		"trimSpace": strings.TrimSpace,
	}
	for k, v := range kubeObjectsFuncMap(dm) {
		f[k] = v
	}
	for k, v := range sprig.FuncMap() {
		f[k] = v
	}
	return f
}