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: printer.go
    path of file: ./repos/mattermost/server/cmd/mmctl/printer
    
    the code of the file until where you have to start completion: // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package printer

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"os/exec"
	"strings"
	"text/template"

	"github.com/fatih/color"
	"github.com/spf13/cobra"
)

const (
	FormatPlain = "plain"
	FormatJSON  = "json"
)

type Printer struct { //nolint
	writer  io.Writer
	eWriter io.Writer

	Format        string
	Single        bool
	NoNewline     bool
	templateFuncs template.FuncMap
	pager         bool
	Quiet         bool
	Lines         []interface{}
	ErrorLines    []interface{}

	cmd        *cobra.Command
	serverAddr string
}

type printOpts struct {
	format    string
	pagerPath string
	single    bool
	usePager  bool
	shortStat bool
	noNewline bool
}

var printer
    
func Flush() error {
	if printer.Quiet {
		return nil
	}

	opts := printOpts{
		format:    printer.Format,
		single:    printer.Single,
		noNewline: printer.NoNewline,
	}

	cmd := printer.cmd
	if cmd != nil {
		shortStat, err := printer.cmd.Flags().GetBool("short-stat")
		if err == nil && printer.cmd.Name() == "list" && printer.cmd.Parent().Name() != "auth" {
			opts.shortStat = shortStat
		}
	}

	b, err := printer.linesToBytes(opts)
	if err != nil {
		return err
	}
	lines := lineCount(b)

	isTTY := checkInteractiveTerminal() == nil
	var enablePager bool
	termHeight, err := termHeight(os.Stdout)
	if err == nil {
		enablePager = isTTY && (termHeight < lines) // calculate if we should enable paging
	}

	pager := os.Getenv("PAGER")
	if enablePager {
		enablePager = pager != ""
	}

	opts.usePager = enablePager && printer.pager
	opts.pagerPath = pager

	err = printer.printBytes(b, opts)
	if err != nil {
		return err
	}

	// after all, print errors
	printer.printErrors()

	defer func() {
		printer.Lines = []interface{}{}
		printer.ErrorLines = []interface{}{}
	}()

	if cmd == nil || cmd.Name() != "list" || printer.cmd.Parent().Name() == "auth" {
		return nil
	}

	// the command is a list command, we may want to
	// take care of the stat flags
	noStat, err := cmd.Flags().GetBool("no-stat")
	if err != nil {
		return err
	}

	// print stats
	switch {
	case noStat:
		// do nothing
	case !opts.shortStat:
		// should not go to pager
		if isTTY && !enablePager {
			fmt.Fprintf(printer.eWriter, "\n") // add a one line space before statistical data
		}
		fallthrough
	case len(printer.Lines) > 0:
		entity := cmd.Parent().Name()
		container := strings.TrimSuffix(printer.serverAddr, "api/v4")
		if container != "" {
			container = fmt.Sprintf(" on %s", container)
		}
		fmt.Fprintf(printer.eWriter, "There are %d %ss%s\n", len(printer.Lines), entity, container)
	}

	return nil
}