Categorygithub.com/jo3-l/yagfuncdata
modulepackage
0.4.0
Repository: https://github.com/jo3-l/yagfuncdata.git
Documentation: pkg.go.dev

# README

yagfuncdata

Automatically up-to-date list of YAGPDB template functions.

Usage

$ lytfs
# outputs a newline-delimited list of YAGPDB template functions

Installation

Assuming that Go is installed, run the following on the command-line:

$ go install github.com/jo3-l/yagfuncdata/cmd/lytfs@latest

Why use yagfuncdata?

yagfuncdata aims to simplify workflows of projects that require a list of YAGPDB template functions, such as language support extensions for editors. For example, one could imagine setting up a cronjob in CI to run yagfuncdata regularly to check for updates and regenerate an asset file when changes are detected.

Note, however, that it is not recommended to run yagfuncdata directly in an application as the command is not infallible. Changes to the structure of relevant files defining template functions may cause the generated list to be incomplete, or, worse, cause the command to fail entirely. Thus, yagfuncdata's output should be manually vetted by a human against a trusted baseline. Hence, the CI cronjob suggested above should ideally generate a PR with its changes (which can then be reviewed and approved), as opposed to committing directly to the repository.

How does it work?

Instead of hardcoding relevant data (which requires manual updates when upstream sources change), yagfuncdata instead automatically generates it on-demand based on the content of files in the YAGPDB project that define template functions. As such, as long as the structure of said files does not change, upstream modifications to the set of available functions are reflected immediately.

For instance, the StandardFuncMap in common/templates/context.go defines the base set of standard functions. It is structured like such:

var (
	StandardFuncMap = map[string]interface{}{
		"name1": func1,
		"name2": func2,
		[...]
	}
)

Observe that each key in the map literal corresponds to a function name. Thus, to generate a list of standard functions, it suffices to parse the content of common/templates/context.go, look up the declaration of StandardFuncMap, and find all keys present in the map literal. This is precisely the approach that yagfuncdata takes in BaseContextFuncSource.collectStandardContextFuncs.

License

yagfuncdata is made available under the MIT license.

# Packages

No description provided by the author

# Functions

DefaultSources returns a set of builtin sources that use the given FileContentProvider.
Fetch retrieves the names of functions available in YAGPDB templates from the sources given.
NewBaseContextFuncSource creates a new Source that provides information regarding functions defined in common/templates/context.go, which include base context and standard functions.
NewBuiltinFuncSource creates a new Source that provides information regarding builtin template functions defined in lib/template/funcs.go.
NewCommandsPluginExtensionFuncSource creates a new Source that provides information regarding extension template functions registered by the command plugin in commands/tmplexec.go.
NewCustomCommandsPluginExtensionFuncSource creates a new Source that provides information regarding extension template functions registered by the custom commands plugin in customcommands/tmplextensions.go.
NewGitHubFileProvider creates a new FileContentProvider that accesses files from a GitHub repository at a specific Git reference using the client provided.
NewInteractionContextFuncSource creates a new Source that provides information regarding interaction context functions defined in lib/template/context_interactions.go.
NewLogsPluginExtensionFuncSource creates a new Source that provides information regarding extension template functions registered by the logs plugin in logs/template_extensions.go.
NewStaticFileProvider creates a new FileContentProvider based on the contents of the provided map.
NewTicketsPluginExtensionFuncSource creates a new Source that provides information regarding extension template functions registered by the tickets plugin in tickets/tmplextensions.go.

# Variables

DefaultFileContentProvider is a FileContentProvider that accesses files on the master branch of the YAGPDB repository using an unauthenticated GitHub client.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
A PluginExtensionFuncSource provides information regarding template functions added by a plugin.
No description provided by the author

# Interfaces

A FileContentProvider provides access to file content.
A Source is a source of YAGPDB template function information.