{"id":19079072,"url":"https://github.com/minekube/brigodier","last_synced_at":"2025-04-30T05:23:46.053Z","repository":{"id":57593693,"uuid":"372642405","full_name":"minekube/brigodier","owner":"minekube","description":"Brigodier is a command parser \u0026 dispatcher, designed and developed for command lines in Minecraft chat commands. It is a complete port from Mojang's \"brigadier\" into Go. Used by our Gate proxy.","archived":false,"fork":false,"pushed_at":"2023-12-15T14:45:48.000Z","size":119,"stargazers_count":17,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-18T20:50:04.167Z","etag":null,"topics":["brigadier","command","commands-framework","go","golang","library","minecraft","mojang","parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/minekube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-31T22:28:23.000Z","updated_at":"2024-08-08T07:43:05.000Z","dependencies_parsed_at":"2024-06-18T21:35:48.641Z","dependency_job_id":"40973b39-ba29-4652-b0c6-d1c3f3379b0f","html_url":"https://github.com/minekube/brigodier","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"bcc73504b79b237b25e629bc692d1633ff68d169"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minekube%2Fbrigodier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minekube%2Fbrigodier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minekube%2Fbrigodier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minekube%2Fbrigodier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minekube","download_url":"https://codeload.github.com/minekube/brigodier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251646328,"owners_count":21620910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brigadier","command","commands-framework","go","golang","library","minecraft","mojang","parser"],"created_at":"2024-11-09T02:13:14.488Z","updated_at":"2025-04-30T05:23:46.029Z","avatar_url":"https://github.com/minekube.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# brigodier\n\n[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/minekube/brigodier?sort=semver)](https://github.com/minekube/brigodier/releases)\n[![Doc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go)](https://pkg.go.dev/go.minekube.com/brigodier)\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/minekube/brigodier?logo=go)](https://golang.org/doc/devel/release.html)\n[![Go Report Card](https://goreportcard.com/badge/go.minekube.com/brigodier)](https://goreportcard.com/report/go.minekube.com/brigodier)\n[![test](https://github.com/minekube/brigodier/workflows/test/badge.svg)](https://github.com/minekube/brigodier/actions?query=workflow%3Atest)\n[![Discord](https://img.shields.io/discord/633708750032863232?logo=discord)](https://discord.gg/6vMDqWE)\n\n**Brigodier is a command parser \u0026 dispatcher, designed and developed\nto provide a simple and flexible command framework.**\n\nIt can be used in many command-line environments such as for\nchat commands in the Minecraft Java Edition.\n\nIt is completely ported to Go from [Mojang's Brigadier](https://github.com/Mojang/brigadier)\n(written in Java), including all features and tests.\n\n## Installation\n\nFor use in your projects go get it with:\n\n```shell\ngo get -u go.minekube.com/brigodier\n```\n\n## Usage\n\nAt the heart of Brigodier, you need a `Dispatcher`.\n\nA command dispatcher holds a \"command tree\", which is a series of\n`CommandNode`s that represent the various possible syntax options that form a valid command.\n\n### Registering a new command\n\nBefore we can start parsing and dispatching commands, we need to build up our command tree.\nEvery registration is an append operation, so you can freely extend existing commands in a project\nwithout needing access to the source code that created them.\n\nCommand registration also encourages the use of a builder pattern to keep code cruft to a minimum.\n\nA \"command\" is a fairly loose term, but typically it means an exit point of the command tree.\nEvery node can have an `Executes` function attached to it, which signifies that if the input stops\nhere then this function will be called with the context so far.\n\nConsider the following example:\n```go\nvar d Dispatcher\n\nd.Register(\n\tLiteral(\"foo\").Then(\n\t\tArgument(\"bar\", Int).\n\t\t\tExecutes(CommandFunc(func(c *CommandContext) error {\n\t\t\t\tfmt.Println(\"Bar is\", c.Int(\"bar\"))\n\t\t\t\treturn nil\n\t\t\t})),\n\t).Executes(CommandFunc(func(c *CommandContext) error {\n\t\tfmt.Println(\"Called foo with no arguments\")\n\t\treturn nil\n\t})),\n)\n``` \n\nThis snippet registers two \"commands\": `foo` and `foo \u003cbar\u003e`.\nIt is also common to refer to the `\u003cbar\u003e` as a \"subcommand\" of `foo`, as it's a child node.\n\nAt the start of the tree is a \"root node\", and it **must** have `LiteralCommandNode`s as children.\nHere, we register one command under the root: `Literal(\"foo\")`, which means \"the user must type the literal string 'foo'\".\n\nUnder that is two extra definitions: a child node for possible further evaluation, or an `executes` block\nif the user input stops here.\n\nThe child node works exactly the same way, but is no longer limited to literals.\nThe other type of node that is now allowed is an `ArgumentCommandNode`, which takes in a name, and an argument type.\n\nArguments can be anything, and you are encouraged to build your own for seamless integration into your own product.\nThere are some builtin ArgumentTypes included, such as `Int` or `String`.\n\nArgument types will be asked to parse input as much as they can, and then store the \"result\" of that argument however\nthey see fit or throw a relevant error if they can't parse.\n\nFor example, an integer argument would parse \"123\" and store it as `123` (`int`), but throw an error if the input were `onetwothree`.\n\nWhen a command function runs, it can access these arguments in the context provided to the registered function.\n\n## Parsing user input\nSo, we've registered some commands, and now we're ready to take in user input.\nIf you're in a rush, you can just call `dispatcher.Execute(ctx, \"foo 123\")` and call it a day.\n\nGo's context.Context can be used to track users/players/etc and\nwill be provided to the command to give context on what's happening (e.g., who has run the command).\n\nIf the command failed or could not parse, some form of `CommandSyntaxError` will be returned,\nor the error that the Command returned.\n\nIf you wish to have more control over the parsing \u0026 executing of commands,\nor wish to cache the parse results, so you can execute it multiple times,\nyou can split it up into two steps:\n\n```go\nparse := dispatcher.Parse(ctx, \"foo 123\")\nerr := dispatcher.Execute(parse)\n``` \n\nThis is highly recommended as the parse step is the most expensive,\nand may be easily cached depending on your application.\n\nYou can also use this to do further introspection on a command,\nbefore (or without) actually running it.\n\n\nThe convenient method to parse and execute a command is:\n```go\nerr := dispatcher.Do(ctx, \"foo 123\")\n``` \n\n### Inspecting a command\n\nIf you `Parse` some input, you can find out what it will perform (if anything) and provide\nhints to the user safely and immediately.\n\nThe parse will never fail, and the `ParseResults` it returns will contain a *possible* context that a command may be called with\n(and from that, you can inspect which nodes the user entered, complete with start/end positions in the input string).\nIt also contains a map of parse exceptions for each command node it encountered. If it couldn't build a valid context, then\nthe reason is inside this exception map.\n\n### Displaying usage info\n\nThere are two forms of \"usage strings\" provided by this library, both require a target node.\n\n- `dispatcher.AllUsage(ctx, node, restricted)`\n  will return a list of all possible commands (executable end-points)\n  under the target node and their human-readable path. If `restricted`,\n  it will ignore commands that `ctx` does not have access to.\n  This will look like [`foo`, `foo \u003cbar\u003e`].\n  \n- `dispatcher.SmartUsage(ctx, node)`\n  will return a map of the child nodes to their \"smart usage\" human-readable path.\n  This tries to squash future-nodes together and show optional \u0026 typed information,\n  and can look like `foo (\u003cbar\u003e)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminekube%2Fbrigodier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminekube%2Fbrigodier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminekube%2Fbrigodier/lists"}