func (a *App) VisibleCategories() []CommandCategory {
	ret := []CommandCategory{}
	for _, category := range a.Categories.Categories() {
		if visible := func() CommandCategory {
			if len(category.VisibleCommands()) > 0 {
				return category
			}
			return nil
		}(); visible != nil {
			ret = append(ret, visible)
		}
	}
	return ret
}
VisibleCategories returns a slice of categories and commands that are
Hidden=false
package cli
import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"
	"sort"
	"time"
)
type App struct {
	Name string
	HelpName string
	Usage string
	UsageText string
	ArgsUsage string
	Version string
	Description string
	Commands []*Command
	Flags []Flag
	EnableShellCompletion bool
	HideHelp bool
	HideVersion bool
	Categories CommandCategories
	ShellComplete ShellCompleteFunc
	Before BeforeFunc
	After AfterFunc
	Action ActionFunc
	CommandNotFound CommandNotFoundFunc
	OnUsageError OnUsageErrorFunc
	Compiled time.Time
	Authors []*Author
	Copyright string
	Writer io.Writer
	ErrWriter io.Writer
	Metadata map[string]interface{}
	ExtraInfo func() map[string]string
	CustomAppHelpTemplate string
	didSetup bool
}
func compileTime() time.Time {
	info, err := os.Stat(os.Args[0])
	if err != nil {
		return time.Now()
	}
	return info.ModTime()
}
func (a *App) Setup() {
	if a.didSetup {
		return
	}
	a.didSetup = true
	if a.Name == "" {
		a.Name = filepath.Base(os.Args[0])
	}
	if a.HelpName == "" {
		a.HelpName = filepath.Base(os.Args[0])
	}
	if a.Usage == "" {
		a.Usage = "A new cli application"
	}
	if a.Version == "" {
		a.Version = "0.0.0"
	}
	if a.ShellComplete == nil {
		a.ShellComplete = DefaultAppComplete
	}
	if a.Action == nil {
		a.Action = helpCommand.Action
	}
	if a.Compiled == (time.Time{}) {
		a.Compiled = compileTime()
	}
	if a.Writer == nil {
		a.Writer = os.Stdout
	}
	newCmds := []*Command{}
	for _, c := range a.Commands {
		if c.HelpName == "" {
			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
		}
		newCmds = append(newCmds, c)
	}
	a.Commands = newCmds
	if a.Command(helpCommand.Name) == nil && !a.HideHelp {
		a.appendCommand(helpCommand)
		if HelpFlag != nil {
			a.appendFlag(HelpFlag)
		}
	}
	if a.EnableShellCompletion {
		a.appendFlag(GenerateCompletionFlag)
		a.appendFlag(InitCompletionFlag)
	}
	if !a.HideVersion {
		a.appendFlag(VersionFlag)
	}
	a.Categories = newCommandCategories()
	for _, command := range a.Commands {
		a.Categories.AddCommand(command.Category, command)
	}
	sort.Sort(a.Categories.(*commandCategories))
	if a.Metadata == nil {
		a.Metadata = make(map[string]interface{})
	}
	if a.Writer == nil {
		a.Writer = os.Stdout
	}
}
func (a *App) Run(arguments []string) (err error) {
	a.Setup()
	shellComplete, arguments := checkShellCompleteFlag(a, arguments)
	set, err := flagSet(a.Name, a.Flags)
	if err != nil {
		return err
	}
	set.SetOutput(ioutil.Discard)
	err = set.Parse(arguments[1:])
	nerr := normalizeFlags(a.Flags, set)
	context := NewContext(a, set, nil)
	if nerr != nil {
		fmt.Fprintln(a.Writer, nerr)
		ShowAppHelp(context)
		return nerr
	}
	context.shellComplete = shellComplete
	if checkCompletions(context) {
		return nil
	}
	if done, cerr := checkInitCompletion(context); done {
		if cerr != nil {
			err = cerr
		} else {
			return nil
		}
	}
	if err != nil {
		if a.OnUsageError != nil {
			err = a.OnUsageError(context, err, false)
			HandleExitCoder(err)
			return err
		}
		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
		ShowAppHelp(context)
		return err
	}
	if !a.HideHelp && checkHelp(context) {
		ShowAppHelp(context)
		return nil
	}
	if !a.HideVersion && checkVersion(context) {
		ShowVersion(context)
		return nil
	}
	if a.After != nil {
		defer func() {
			if afterErr := a.After(context); afterErr != nil {
				if err != nil {
					err = newMultiError(err, afterErr)
				} else {
					err = afterErr
				}
			}
		}()
	}
	if a.Before != nil {
		beforeErr := a.Before(context)
		if beforeErr != nil {
			ShowAppHelp(context)
			HandleExitCoder(beforeErr)
			err = beforeErr
			return err
		}
	}
	args := context.Args()
	if args.Present() {
		name := args.First()
		c := a.Command(name)
		if c != nil {
			return c.Run(context)
		}
	}
	if a.Action == nil {
		a.Action = helpCommand.Action
	}
	err = a.Action(context)
	HandleExitCoder(err)
	return err
}
func (a *App) RunAsSubcommand(ctx *Context) (err error) {
	a.Setup()
	if len(a.Commands) > 0 {
		if a.Command(helpCommand.Name) == nil && !a.HideHelp {
			a.appendCommand(helpCommand)
			if HelpFlag != nil {
				a.appendFlag(HelpFlag)
			}
		}
	}
	newCmds := []*Command{}
	for _, c := range a.Commands {
		if c.HelpName == "" {
			c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
		}
		newCmds = append(newCmds, c)
	}
	a.Commands = newCmds
	if a.EnableShellCompletion {
		a.appendFlag(GenerateCompletionFlag)
	}
	set, err := flagSet(a.Name, a.Flags)
	if err != nil {
		return err
	}
	set.SetOutput(ioutil.Discard)
	err = set.Parse(ctx.Args().Tail())
	nerr := normalizeFlags(a.Flags, set)
	context := NewContext(a, set, ctx)
	if nerr != nil {
		fmt.Fprintln(a.Writer, nerr)
		fmt.Fprintln(a.Writer)
		if len(a.Commands) > 0 {
			ShowSubcommandHelp(context)
		} else {
			ShowCommandHelp(ctx, context.Args().First())
		}
		return nerr
	}
	if checkCompletions(context) {
		return nil
	}
	if err != nil {
		if a.OnUsageError != nil {
			err = a.OnUsageError(context, err, true)
			HandleExitCoder(err)
			return err
		}
		fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
		ShowSubcommandHelp(context)
		return err
	}
	if len(a.Commands) > 0 {
		if checkSubcommandHelp(context) {
			return nil
		}
	} else {
		if checkCommandHelp(ctx, context.Args().First()) {
			return nil
		}
	}
	if a.After != nil {
		defer func() {
			afterErr := a.After(context)
			if afterErr != nil {
				HandleExitCoder(err)
				if err != nil {
					err = newMultiError(err, afterErr)
				} else {
					err = afterErr
				}
			}
		}()
	}
	if a.Before != nil {
		beforeErr := a.Before(context)
		if beforeErr != nil {
			HandleExitCoder(beforeErr)
			err = beforeErr
			return err
		}
	}
	args := context.Args()
	if args.Present() {
		name := args.First()
		c := a.Command(name)
		if c != nil {
			return c.Run(context)
		}
	}
	err = a.Action(context)
	HandleExitCoder(err)
	return err
}
func (a *App) Command(name string) *Command {
	for _, c := range a.Commands {
		if c.HasName(name) {
			return c
		}
	}
	return nil
}