// ----- helpers
178808
func verifyAud(aud string, cmp string, required bool) bool {
	if aud == "" {
		return !required
	}
	if subtle.ConstantTimeCompare([]byte(aud), []byte(cmp)) != 0 {
		return true
	} else {
		return false
	}
}
1314674
func (p *parser) parseHelperNameOrSexpr() ast.Node {
	if p.isSexpr() {
		// sexpr
		return p.parseSexpr()
	}

	// helperName
	return p.parseHelperName()
}
255783
func (v *evalVisitor) callHelper(name string, helper reflect.Value, node *ast.Expression) interface{} {
	result := v.callFunc(name, helper, v.helperOptions(node))
	if !result.IsValid() {
		return nil
	}

	// @todo We maybe want to ensure here that helper returned a string or a SafeString
	return result.Interface()
}
38264
func (c *Comandante) IncludeHelp() {
	cmd := createHelpCommand(c, os.Stderr)
	c.RegisterCommand(cmd)
}
360762
func (e *Runner) Help(cmdUse string) string {
	e.prepareForExecution()

	// computes the max length of for each phase use line
	maxLength := 0
	e.visitAll(func(p *phaseRunner) error {
		if !p.Hidden && !p.RunAllSiblings {
			length := len(p.use)
			if maxLength < length {
				maxLength = length
			}
		}
		return nil
	})

	// prints the list of phases indented by level and formatted using the maxlength
	// the list is enclosed in a mardown code block for ensuring better readability in the public web site
	line := fmt.Sprintf("The %q command executes the following phases:\n", cmdUse)
	line += "```\n"
	offset := 2
	e.visitAll(func(p *phaseRunner) error {
		if !p.Hidden && !p.RunAllSiblings {
			padding := maxLength - len(p.use) + offset
			line += strings.Repeat(" ", offset*p.level) // indentation
			line += p.use                               // name + aliases
			line += strings.Repeat(" ", padding)        // padding right up to max length (+ offset for spacing)
			line += p.Short                             // phase short description
			line += "\n"
		}

		return nil
	})
	line += "```"
	return line
}
765598
func (v *evalVisitor) isHelperCall(node *ast.Expression) bool {
	if helperName := node.HelperName(); helperName != "" {
		return v.findHelper(helperName) != zero
	}
	return false
}
419653
func (h *HelperMap) Add(key string, helper interface{}) error {
	h.moot.Lock()
	defer h.moot.Unlock()
	if h.helpers == nil {
		h.helpers = map[string]interface{}{}
	}
	err := h.validateHelper(key, helper)
	if err != nil {
		return errors.WithStack(err)
	}
	h.helpers[key] = helper
	return nil
}
1088683
func FilteredHelpFunc(include []string, f HelpFunc) HelpFunc {
	return func(commands map[string]CommandFactory) string {
		set := make(map[string]struct{})
		for _, k := range include {
			set[k] = struct{}{}
		}

		filtered := make(map[string]CommandFactory)
		for k, f := range commands {
			if _, ok := set[k]; ok {
				filtered[k] = f
			}
		}

		return f(filtered)
	}
}
1033546
func (s *Storage) MergeHelper(ctx context.Context,
	convID chat1.ConversationID, uid gregor1.UID, msgs []chat1.MessageUnboxed, expunge *chat1.Expunge) (res MergeResult, err Error) {
	defer s.Trace(ctx, func() error { return err }, "MergeHelper")()
	lock := locks.StorageLockTab.AcquireOnName(ctx, s.G(), convID.String())
	defer lock.Release(ctx)

	s.Debug(ctx, "MergeHelper: convID: %s uid: %s num msgs: %d", convID, uid, len(msgs))

	// Fetch secret key
	key, ierr := GetSecretBoxKey(ctx, s.G().ExternalG(), DefaultSecretUI)
	if ierr != nil {
		return res, MiscError{Msg: "unable to get secret key: " + ierr.Error()}
	}

	ctx, err = s.engine.Init(ctx, key, convID, uid)
	if err != nil {
		return res, err
	}

	// Write out new data into blocks
	if err = s.engine.WriteMessages(ctx, convID, uid, msgs); err != nil {
		return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
	}

	// Update supersededBy pointers
	updateRes, err := s.updateAllSupersededBy(ctx, convID, uid, msgs)
	if err != nil {
		return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
	}
	res.ReactionTargets = updateRes.reactionTargets
	res.UnfurlTargets = updateRes.unfurlTargets
	res.RepliesAffected = updateRes.repliesAffected

	if err = s.updateMinDeletableMessage(ctx, convID, uid, msgs); err != nil {
		return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
	}

	// Process any DeleteHistory messages
	expunged, err := s.handleDeleteHistory(ctx, convID, uid, msgs, expunge)
	if err != nil {
		return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
	}
	res.Expunged = expunged

	exploded, err := s.explodeExpiredMessages(ctx, convID, uid, msgs)
	if err != nil {
		return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
	}
	res.Exploded = exploded

	// Update max msg ID if needed
	if len(msgs) > 0 {
		if err := s.idtracker.bumpMaxMessageID(ctx, convID, uid, msgs[0].GetMessageID()); err != nil {
			return res, s.maybeNukeLocked(ctx, false, err, convID, uid)
		}
	}

	// queue search index update in the background
	go s.G().Indexer.Add(ctx, convID, uid, msgs)

	return res, nil
}
145963
func HelperNameStr(node Node) (string, bool) {
	// PathExpression
	if str, ok := PathExpressionStr(node); ok {
		return str, ok
	}

	// Literal
	if str, ok := LiteralStr(node); ok {
		return str, ok
	}

	return "", false
}
278335
func ensureValidHelper(name string, funcValue reflect.Value) {
	if funcValue.Kind() != reflect.Func {
		panic(fmt.Errorf("Helper must be a function: %s", name))
	}

	funcType := funcValue.Type()

	if funcType.NumOut() != 1 {
		panic(fmt.Errorf("Helper function must return a string or a SafeString: %s", name))
	}

	// @todo Check if first returned value is a string, SafeString or interface{} ?
}
606785
func (cmd *Cmd) help(line string) (stop bool) {
	fmt.Println("")

	if line == "--all" {
		fmt.Println("Available commands (use 'help <topic>'):")
		fmt.Println("================================================================")
		for _, c := range cmd.commandNames {
			fmt.Printf("%v: ", c)
			cmd.Commands[c].HelpFunc()
		}
	} else if len(line) == 0 {
		fmt.Println("Available commands (use 'help <topic>'):")
		fmt.Println("================================================================")

		max := 0

		for _, c := range cmd.commandNames {
			if len(c) > max {
				max = len(c)
			}
		}

		tp := pretty.NewTabPrinter(80 / (max + 1))
		tp.TabWidth(max + 1)

		for _, c := range cmd.commandNames {
			tp.Print(c)
		}
		tp.Println()
	} else {
		if c, ok := cmd.Commands[line]; ok {
			c.HelpFunc()
		} else {
			fmt.Println("unknown command or function")
		}
	}

	fmt.Println("")
	return
}
145161
func help(args []string) {
	if len(args) == 0 {
		printUsage(os.Stdout)
		return
	}
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "usage: gvt help command\n\nToo many arguments given.\n")
		os.Exit(2)
	}

	arg := args[0]

	// 'gvt help documentation' generates alldocs.go.
	if arg == "documentation" {
		var u bytes.Buffer
		printUsage(&u)
		f, _ := os.Create("alldocs.go")
		tmpl(f, documentationTemplate, struct {
			Usage    string
			Commands []*Command
		}{
			u.String(),
			commands,
		})
		f.Close()
		return
	}

	for _, cmd := range commands {
		if cmd.Name == arg {
			tmpl(os.Stdout, helpTemplate, cmd)
			return
		}
	}

	fmt.Fprintf(os.Stderr, "Unknown help topic %#q. Run 'gvt help'.\n", arg)
	os.Exit(2)
}
572044
func AppHelpers(manifest map[string]string) template.FuncMap {
	return template.FuncMap{
		"liveReload": liveReloadHelper,
		"jsPath":     func(relpath string) string { return manifestHelper("js", relpath, manifest) },
		"cssPath":    func(relpath string) string { return manifestHelper("css", relpath, manifest) },
		"imgPath":    func(relpath string) string { return manifestHelper("img", relpath, manifest) },
		"videoPath":  func(relpath string) string { return manifestHelper("video", relpath, manifest) },
		"audioPath":  func(relpath string) string { return manifestHelper("audio", relpath, manifest) },
		"fontPath":   func(relpath string) string { return manifestHelper("font", relpath, manifest) },
		"assetPath": func(relpath string) string {
			v, ok := manifest[relpath]
			if !ok {
				return "/assets/" + relpath
			}
			return "/assets/" + v
		},

		// wrap full asset paths in include tags
		"cssTag": cssTag,
		"jsTag":  jsTag,

		"joinPath": func(pieces ...string) string { return strings.Join(pieces, "/") },

		// return all javascript include tags for all twitter bootstrap js plugins
		// for the default bootstrap install.
		"jsBootstrap": jsBootstrap,
	}
}
845524
func eachHelper(context interface{}, options *Options) interface{} {
	if !IsTrue(context) {
		return options.Inverse()
	}

	result := ""

	val := reflect.ValueOf(context)
	switch val.Kind() {
	case reflect.Array, reflect.Slice:
		for i := 0; i < val.Len(); i++ {
			// computes private data
			data := options.newIterDataFrame(val.Len(), i, nil)

			// evaluates block
			result += options.evalBlock(val.Index(i).Interface(), data, i)
		}
	case reflect.Map:
		// note: a go hash is not ordered, so result may vary, this behaviour differs from the JS implementation
		keys := val.MapKeys()
		for i := 0; i < len(keys); i++ {
			key := keys[i].Interface()
			ctx := val.MapIndex(keys[i]).Interface()

			// computes private data
			data := options.newIterDataFrame(len(keys), i, key)

			// evaluates block
			result += options.evalBlock(ctx, data, key)
		}
	case reflect.Struct:
		var exportedFields []int

		// collect exported fields only
		for i := 0; i < val.NumField(); i++ {
			if tField := val.Type().Field(i); tField.PkgPath == "" {
				exportedFields = append(exportedFields, i)
			}
		}

		for i, fieldIndex := range exportedFields {
			key := val.Type().Field(fieldIndex).Name
			ctx := val.Field(fieldIndex).Interface()

			// computes private data
			data := options.newIterDataFrame(len(exportedFields), i, key)

			// evaluates block
			result += options.evalBlock(ctx, data, key)
		}
	}

	return result
}
767753
func (c *Command) addHelpGroup(showHelp func() error) *Group {
	var help struct {
		ShowHelp func() error `short:"h" long:"help" description:"Show this help message"`
	}

	help.ShowHelp = showHelp
	ret, _ := c.AddGroup("Help Options", "", &help)
	ret.isBuiltinHelp = true

	return ret
}
275177
func (f *Fn) HelperParamList() string {
	return join(f.Params, func(p *Param) string { return p.Name + " " + p.HelperType() }, ", ")
}