You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: generate.go
    path of file: ./repos/rill/cli/cmd/docs
    
    the code of the file until where you have to start completion: package docs

import (
	"bytes"
	"fmt"
	"io"
	"io/fs"
	"log"
	"os"
	"path/filepath"
	"sort"

	"github.com/rilldata/rill/cli/pkg/cmdu
    
func genMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
	if cmd.Hidden {
		return nil
	}

	for _, c := range cmd.Commands() {
		if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
			continue
		}

		sd := dir
		if cmd.Parent() != nil {
			sd = filepath.Join(dir, cmd.Name())
		}

		if err := genMarkdownTreeCustom(c, sd, filePrepender); err != nil {
			return err
		}
	}

	nm := cmd.Name()
	if cmd.Parent() == nil {
		nm = "cli"
	}

	filename := filepath.Join(dir, nm+".md")
	if len(cmd.Commands()) > 0 && cmd.Parent() != nil {
		dir = filepath.Join(dir, cmd.Name())
		filename = filepath.Join(dir, nm+".md")
	}

	if _, err := os.Stat(dir); os.IsNotExist(err) {
		if err := os.Mkdir(dir, fs.ModePerm); err != nil {
			return err
		}
	}

	f, err := os.Create(filename)
	if err != nil {
		return err
	}

	defer f.Close()

	if _, err := f.WriteString(filePrepender(filename)); err != nil {
		return err
	}

	return genMarkdownCustom(cmd, f)
}