{"id":37163030,"url":"https://github.com/streamdal/kong","last_synced_at":"2026-01-14T19:23:47.109Z","repository":{"id":46759846,"uuid":"410714834","full_name":"streamdal/kong","owner":"streamdal","description":"Kong is a command-line parser for Go","archived":false,"fork":true,"pushed_at":"2021-09-28T03:15:34.000Z","size":1107,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T14:19:46.252Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"alecthomas/kong","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamdal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["alecthomas"]}},"created_at":"2021-09-27T02:17:30.000Z","updated_at":"2024-06-21T14:19:46.253Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/streamdal/kong","commit_stats":null,"previous_names":["batchcorp/kong"],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/streamdal/kong","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Fkong","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Fkong/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Fkong/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Fkong/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamdal","download_url":"https://codeload.github.com/streamdal/kong/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamdal%2Fkong/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28432587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-14T19:23:46.333Z","updated_at":"2026-01-14T19:23:47.100Z","avatar_url":"https://github.com/streamdal.png","language":"Go","readme":"\u003c!-- markdownlint-disable MD013 MD033 --\u003e\n\u003cp align=\"center\"\u003e\u003cimg width=\"90%\" src=\"kong.png\" /\u003e\u003c/p\u003e\n\n# Kong is a command-line parser for Go\n[![](https://godoc.org/github.com/alecthomas/kong?status.svg)](http://godoc.org/github.com/alecthomas/kong) [![CircleCI](https://img.shields.io/circleci/project/github/alecthomas/kong.svg)](https://circleci.com/gh/alecthomas/kong) [![Go Report Card](https://goreportcard.com/badge/github.com/alecthomas/kong)](https://goreportcard.com/report/github.com/alecthomas/kong) [![Slack chat](https://img.shields.io/static/v1?logo=slack\u0026style=flat\u0026label=slack\u0026color=green\u0026message=gophers)](https://gophers.slack.com/messages/CN9DS8YF3)\n\n\u003c!-- TOC depthfrom:2 updateonsave:true withlinks:true --\u003e\n\n**NOTE**: This is a fork of [alecthomas/kong](https://github.com/alecthomas/kong)\nthat includes protobuf-related functionality.\n\n- [Introduction](#introduction)\n- [Help](#help)\n    - [Help as a user of a Kong application](#help-as-a-user-of-a-kong-application)\n    - [Defining help in Kong](#defining-help-in-kong)\n- [Command handling](#command-handling)\n    - [Switch on the command string](#switch-on-the-command-string)\n    - [Attach a Run... error method to each command](#attach-a-run-error-method-to-each-command)\n- [Hooks: BeforeResolve, BeforeApply, AfterApply and the Bind option](#hooks-beforeresolve-beforeapply-afterapply-and-the-bind-option)\n- [Flags](#flags)\n- [Commands and sub-commands](#commands-and-sub-commands)\n- [Branching positional arguments](#branching-positional-arguments)\n- [Terminating positional arguments](#terminating-positional-arguments)\n- [Slices](#slices)\n- [Maps](#maps)\n- [Custom named decoders](#custom-named-decoders)\n- [Supported field types](#supported-field-types)\n- [Custom decoders mappers](#custom-decoders-mappers)\n- [Supported tags](#supported-tags)\n- [Plugins](#plugins)\n- [Dynamic Commands](#dynamic-commands)\n- [Variable interpolation](#variable-interpolation)\n- [Validation](#validation)\n- [Modifying Kong's behaviour](#modifying-kongs-behaviour)\n    - [Namehelp and Descriptionhelp - set the application name description](#namehelp-and-descriptionhelp---set-the-application-name-description)\n    - [Configurationloader, paths... - load defaults from configuration files](#configurationloader-paths---load-defaults-from-configuration-files)\n    - [Resolver... - support for default values from external sources](#resolver---support-for-default-values-from-external-sources)\n    - [*Mapper... - customising how the command-line is mapped to Go values](#mapper---customising-how-the-command-line-is-mapped-to-go-values)\n    - [ConfigureHelpHelpOptions and HelpHelpFunc - customising help](#configurehelphelpoptions-and-helphelpfunc---customising-help)\n    - [Bind... - bind values for callback hooks and Run methods](#bind---bind-values-for-callback-hooks-and-run-methods)\n    - [Other options](#other-options)\n\n\u003c!-- /TOC --\u003e\n\n## Introduction\n\nKong aims to support arbitrarily complex command-line structures with as little developer effort as possible.\n\nTo achieve that, command-lines are expressed as Go types, with the structure and tags directing how the command line is mapped onto the struct.\n\nFor example, the following command-line:\n\n    shell rm [-f] [-r] \u003cpaths\u003e ...\n    shell ls [\u003cpaths\u003e ...]\n\nCan be represented by the following command-line structure:\n\n```go\npackage main\n\nimport \"github.com/batchcorp/kong\"\n\nvar CLI struct {\n  Rm struct {\n    Force     bool `help:\"Force removal.\"`\n    Recursive bool `help:\"Recursively remove files.\"`\n\n    Paths []string `arg:\"\" name:\"path\" help:\"Paths to remove.\" type:\"path\"`\n  } `cmd:\"\" help:\"Remove files.\"`\n\n  Ls struct {\n    Paths []string `arg:\"\" optional:\"\" name:\"path\" help:\"Paths to list.\" type:\"path\"`\n  } `cmd:\"\" help:\"List paths.\"`\n}\n\nfunc main() {\n  ctx := kong.Parse(\u0026CLI)\n  switch ctx.Command() {\n  case \"rm \u003cpath\u003e\":\n  case \"ls\":\n  default:\n    panic(ctx.Command())\n  }\n}\n```\n\n## Help\n\n### Help as a user of a Kong application\n\nEvery Kong application includes a `--help` flag that will display auto-generated help.\n\neg.\n\n    $ shell --help\n    usage: shell \u003ccommand\u003e\n\n    A shell-like example app.\n\n    Flags:\n      --help   Show context-sensitive help.\n      --debug  Debug mode.\n\n    Commands:\n      rm \u003cpath\u003e ...\n        Remove files.\n\n      ls [\u003cpath\u003e ...]\n        List paths.\n\nIf a command is provided, the help will show full detail on the command including all available flags.\n\neg.\n\n    $ shell --help rm\n    usage: shell rm \u003cpaths\u003e ...\n\n    Remove files.\n\n    Arguments:\n      \u003cpaths\u003e ...  Paths to remove.\n\n    Flags:\n          --debug        Debug mode.\n\n      -f, --force        Force removal.\n      -r, --recursive    Recursively remove files.\n\n### Defining help in Kong\n\nHelp is automatically generated from the command-line structure itself,\nincluding `help:\"\"` and other tags. [Variables](#variable-interpolation) will\nalso be interpolated into the help string.\n\nFinally, any command, argument, or flag type implementing the interface\n`Help() string` will have this function called to retrieve the help string.\nThis allows for much more descriptive text than can fit in Go tags.\n\n## Command handling\n\nThere are two ways to handle commands in Kong.\n\n### Switch on the command string\n\nWhen you call `kong.Parse()` it will return a unique string representation of the command. Each command branch in the hierarchy will be a bare word and each branching argument or required positional argument will be the name surrounded by angle brackets. Here's an example:\n\nThere's an example of this pattern [here](https://github.com/alecthomas/kong/blob/master/_examples/shell/main.go).\n\neg.\n\n```go\npackage main\n\nimport \"github.com/batchcorp/kong\"\n\nvar CLI struct {\n  Rm struct {\n    Force     bool `help:\"Force removal.\"`\n    Recursive bool `help:\"Recursively remove files.\"`\n\n    Paths []string `arg:\"\" name:\"path\" help:\"Paths to remove.\" type:\"path\"`\n  } `cmd:\"\" help:\"Remove files.\"`\n\n  Ls struct {\n    Paths []string `arg:\"\" optional:\"\" name:\"path\" help:\"Paths to list.\" type:\"path\"`\n  } `cmd:\"\" help:\"List paths.\"`\n}\n\nfunc main() {\n  ctx := kong.Parse(\u0026CLI)\n  switch ctx.Command() {\n  case \"rm \u003cpath\u003e\":\n  case \"ls\":\n  default:\n    panic(ctx.Command())\n  }\n}\n```\n\nThis has the advantage that it is convenient, but the downside that if you modify your CLI structure, the strings may change. This can be fragile.\n\n### Attach a `Run(...) error` method to each command\n\nA more robust approach is to break each command out into their own structs:\n\n1. Break leaf commands out into separate structs.\n2. Attach a `Run(...) error` method to all leaf commands.\n3. Call `kong.Kong.Parse()` to obtain a `kong.Context`.\n4. Call `kong.Context.Run(bindings...)` to call the selected parsed command.\n\nOnce a command node is selected by Kong it will search from that node back to the root. Each\nencountered command node with a `Run(...) error` will be called in reverse order. This allows\nsub-trees to be re-used fairly conveniently.\n\nIn addition to values bound with the `kong.Bind(...)` option, any values\npassed through to `kong.Context.Run(...)` are also bindable to the target's\n`Run()` arguments.\n\nFinally, hooks can also contribute bindings via `kong.Context.Bind()` and `kong.Context.BindTo()`.\n\nThere's a full example emulating part of the Docker CLI [here](https://github.com/alecthomas/kong/tree/master/_examples/docker).\n\neg.\n\n```go\ntype Context struct {\n  Debug bool\n}\n\ntype RmCmd struct {\n  Force     bool `help:\"Force removal.\"`\n  Recursive bool `help:\"Recursively remove files.\"`\n\n  Paths []string `arg:\"\" name:\"path\" help:\"Paths to remove.\" type:\"path\"`\n}\n\nfunc (r *RmCmd) Run(ctx *Context) error {\n  fmt.Println(\"rm\", r.Paths)\n  return nil\n}\n\ntype LsCmd struct {\n  Paths []string `arg:\"\" optional:\"\" name:\"path\" help:\"Paths to list.\" type:\"path\"`\n}\n\nfunc (l *LsCmd) Run(ctx *Context) error {\n  fmt.Println(\"ls\", l.Paths)\n  return nil\n}\n\nvar cli struct {\n  Debug bool `help:\"Enable debug mode.\"`\n\n  Rm RmCmd `cmd:\"\" help:\"Remove files.\"`\n  Ls LsCmd `cmd:\"\" help:\"List paths.\"`\n}\n\nfunc main() {\n  ctx := kong.Parse(\u0026cli)\n  // Call the Run() method of the selected parsed command.\n  err := ctx.Run(\u0026Context{Debug: cli.Debug})\n  ctx.FatalIfErrorf(err)\n}\n\n```\n\n## Hooks: BeforeResolve(), BeforeApply(), AfterApply() and the Bind() option\n\nIf a node in the grammar has a `BeforeResolve(...)`, `BeforeApply(...) error` and/or `AfterApply(...) error` method, those methods will be called before validation/assignment and after validation/assignment, respectively.\n\nThe `--help` flag is implemented with a `BeforeApply` hook.\n\nArguments to hooks are provided via the `Run(...)` method or `Bind(...)` option. `*Kong`, `*Context` and `*Path` are also bound and finally, hooks can also contribute bindings via `kong.Context.Bind()` and `kong.Context.BindTo()`.\n\neg.\n\n```go\n// A flag with a hook that, if triggered, will set the debug loggers output to stdout.\ntype debugFlag bool\n\nfunc (d debugFlag) BeforeApply(logger *log.Logger) error {\n  logger.SetOutput(os.Stdout)\n  return nil\n}\n\nvar cli struct {\n  Debug debugFlag `help:\"Enable debug logging.\"`\n}\n\nfunc main() {\n  // Debug logger going to discard.\n  logger := log.New(ioutil.Discard, \"\", log.LstdFlags)\n\n  ctx := kong.Parse(\u0026cli, kong.Bind(logger))\n\n  // ...\n}\n```\n\n## Flags\n\nAny [mapped](#mapper---customising-how-the-command-line-is-mapped-to-go-values) field in the command structure *not* tagged with `cmd` or `arg` will be a flag. Flags are optional by default.\n\neg. The command-line `app [--flag=\"foo\"]` can be represented by the following.\n\n```go\ntype CLI struct {\n  Flag string\n}\n```\n\n## Commands and sub-commands\n\nSub-commands are specified by tagging a struct field with `cmd`. Kong supports arbitrarily nested commands.\n\neg. The following struct represents the CLI structure `command [--flag=\"str\"] sub-command`.\n\n```go\ntype CLI struct {\n  Command struct {\n    Flag string\n\n    SubCommand struct {\n    } `cmd`\n  } `cmd`\n}\n```\n\nIf a sub-command is tagged with `default:\"1\"` it will be selected if there are no further arguments. If a sub-command is tagged with `default:\"withargs\"` it will be selected even if there are further arguments or flags and those arguments or flags are valid for the sub-command. This allows the user to omit the sub-command name on the CLI if its arguments/flags are not ambiguous with the sibling commands or flags.\n\n## Branching positional arguments\n\nIn addition to sub-commands, structs can also be configured as branching positional arguments.\n\nThis is achieved by tagging an [unmapped](#mapper---customising-how-the-command-line-is-mapped-to-go-values) nested struct field with `arg`, then including a positional argument field inside that struct _with the same name_. For example, the following command structure:\n\n    app rename \u003cname\u003e to \u003cname\u003e\n\nCan be represented with the following:\n\n```go\nvar CLI struct {\n  Rename struct {\n    Name struct {\n      Name string `arg` // \u003c-- NOTE: identical name to enclosing struct field.\n      To struct {\n        Name struct {\n          Name string `arg`\n        } `arg`\n      } `cmd`\n    } `arg`\n  } `cmd`\n}\n```\n\nThis looks a little verbose in this contrived example, but typically this will not be the case.\n\n## Terminating positional arguments\n\nIf a [mapped type](#mapper---customising-how-the-command-line-is-mapped-to-go-values) is tagged with `arg` it will be treated as the final positional values to be parsed on the command line.\n\nIf a positional argument is a slice, all remaining arguments will be appended to that slice.\n\n## Slices\n\nSlice values are treated specially. First the input is split on the `sep:\"\u003crune\u003e\"` tag (defaults to `,`), then each element is parsed by the slice element type and appended to the slice. If the same value is encountered multiple times, elements continue to be appended.\n\nTo represent the following command-line:\n\n    cmd ls \u003cfile\u003e \u003cfile\u003e ...\n\nYou would use the following:\n\n```go\nvar CLI struct {\n  Ls struct {\n    Files []string `arg:\"\" type:\"existingfile\"`\n  } `cmd`\n}\n```\n\n## Maps\n\nMaps are similar to slices except that only one key/value pair can be assigned per value, and the `sep` tag denotes the assignment character and defaults to `=`.\n\nTo represent the following command-line:\n\n    cmd config set \u003ckey\u003e=\u003cvalue\u003e \u003ckey\u003e=\u003cvalue\u003e ...\n\nYou would use the following:\n\n```go\nvar CLI struct {\n  Config struct {\n    Set struct {\n      Config map[string]float64 `arg:\"\" type:\"file:\"`\n    } `cmd`\n  } `cmd`\n}\n```\n\nFor flags, multiple key+value pairs should be separated by `mapsep:\"rune\"` tag (defaults to `;`) eg. `--set=\"key1=value1;key2=value2\"`.\n\n## Custom named decoders\n\nKong includes a number of builtin custom type mappers. These can be used by\nspecifying the tag `type:\"\u003ctype\u003e\"`. They are registered with the option\nfunction `NamedMapper(name, mapper)`.\n\n| Name              | Description\n|-------------------|---------------------------------------------------\n| `path`            | A path. ~ expansion is applied. `-` is accepted for stdout, and will be passed unaltered.\n| `existingfile`    | An existing file. ~ expansion is applied. `-` is accepted for stdin, and will be passed unaltered.\n| `existingdir`     | An existing directory. ~ expansion is applied.\n| `counter`         | Increment a numeric field. Useful for `-vvv`. Can accept `-s`, `--long` or `--long=N`.\n\n\nSlices and maps treat type tags specially. For slices, the `type:\"\"` tag\nspecifies the element type. For maps, the tag has the format\n`tag:\"[\u003ckey\u003e]:[\u003cvalue\u003e]\"` where either may be omitted.\n\n## Supported field types\n\n\n## Custom decoders (mappers)\n\n\nAny field implementing `encoding.TextUnmarshaler` or `json.Unmarshaler` will use those interfaces\nfor decoding values. Kong also includes builtin support for many common Go types:\n\n| Type                | Description\n|---------------------|--------------------------------------------\n| `time.Duration`     | Populated using `time.ParseDuration()`.\n| `time.Time`         | Populated using `time.Parse()`. Format defaults to RFC3339 but can be overridden with the `format:\"X\"` tag.\n| `*os.File`          | Path to a file that will be opened, or `-` for `os.Stdin`. File must be closed by the user.\n| `*url.URL`          | Populated with `url.Parse()`.\n\nFor more fine-grained control, if a field implements the\n[MapperValue](https://godoc.org/github.com/alecthomas/kong#MapperValue)\ninterface it will be used to decode arguments into the field.\n\n## Supported tags\n\nTags can be in two forms:\n\n1. Standard Go syntax, eg. `kong:\"required,name='foo'\"`.\n2. Bare tags, eg. `required:\"\" name:\"foo\"`\n\nBoth can coexist with standard Tag parsing.\n\nTag                    | Description\n-----------------------| -------------------------------------------\n`cmd:\"\"`               | If present, struct is a command.\n`arg:\"\"`               | If present, field is an argument.\n`env:\"X\"`              | Specify envar to use for default value.\n`name:\"X\"`             | Long name, for overriding field name.\n`help:\"X\"`             | Help text.\n`type:\"X\"`             | Specify [named types](#custom-named-decoders) to use.\n`placeholder:\"X\"`      | Placeholder text.\n`default:\"X\"`          | Default value.\n`default:\"1\"`          | On a command, make it the default.\n`default:\"withargs\"`   | On a command, make it the default and allow args/flags from that command\n`short:\"X\"`            | Short name, if flag.\n`aliases:\"X,Y\"`        | One or more aliases (for cmd).\n`required:\"\"`          | If present, flag/arg is required.\n`optional:\"\"`          | If present, flag/arg is optional.\n`hidden:\"\"`            | If present, command or flag is hidden.\n`negatable:\"\"`         | If present on a `bool` field, supports prefixing a flag with `--no-` to invert the default value\n`format:\"X\"`           | Format for parsing input, if supported.\n`sep:\"X\"`              | Separator for sequences (defaults to \",\"). May be `none` to disable splitting.\n`mapsep:\"X\"`           | Separator for maps (defaults to \";\"). May be `none` to disable splitting.\n`enum:\"X,Y,...\"`       | Set of valid values allowed for this flag. An enum field must be `required` or have a valid `default`.\n`group:\"X\"`            | Logical group for a flag or command.\n`xor:\"X,Y,...\"`        | Exclusive OR groups for flags. Only one flag in the group can be used which is restricted within the same command. When combined with `required`, at least one of the `xor` group will be required.\n`prefix:\"X\"`           | Prefix for all sub-flags.\n`set:\"K=V\"`            | Set a variable for expansion by child elements. Multiples can occur.\n`embed:\"\"`             | If present, this field's children will be embedded in the parent. Useful for composition.\n`passthrough:\"\"`       | If present, this positional argument stops flag parsing when encountered, as if `--` was processed before. Useful for external command wrappers, like `exec`.\n\n### Protobuf-specific settings\n\nTag                    | Description\n-----------------------| -------------------------------------------\n`type:\"pbenum\"`        | If present, `kong` will treat the field as if it was generated via protoc. `kong` will attempt to automatically read all of the available enums and validate that the input is a valid option.\n`pbenum_strip_prefix:\"X\"`  | When used with `type:\"pbenum\"`, `kong` will strip the prefix from the enum names before exposing them in the CLI.\n`pbenum_lowercase`     | When used with `type:\"pbenum\"`, `kong` will lowercase the enum names before exposing them in the CLI.\n`-`                    | Ignore the field. Useful for adding non-CLI fields to a configuration struct. e.g `` `kong:\"-\"` ``\n\n## Plugins\n\nKong CLI's can be extended by embedding the `kong.Plugin` type and populating it with pointers to Kong annotated structs. For example:\n\n```go\nvar pluginOne struct {\n  PluginOneFlag string\n}\nvar pluginTwo struct {\n  PluginTwoFlag string\n}\nvar cli struct {\n  BaseFlag string\n  kong.Plugins\n}\ncli.Plugins = kong.Plugins{\u0026pluginOne, \u0026pluginTwo}\n```\n\nAdditionally if an interface type is embedded, it can also be populated with a Kong annotated struct.\n\n## Dynamic Commands\n\nWhile plugins give complete control over extending command-line interfaces, Kong\nalso supports dynamically adding commands via `kong.DynamicCommand()`.\n\n## Variable interpolation\n\nKong supports limited variable interpolation into help strings, enum lists and\ndefault values.\n\nVariables are in the form:\n\n    ${\u003cname\u003e}\n    ${\u003cname\u003e=\u003cdefault\u003e}\n\nVariables are set with the `Vars{\"key\": \"value\", ...}` option. Undefined\nvariable references in the grammar without a default will result in an error at\nconstruction time.\n\nVariables can also be set via the `set:\"K=V\"` tag. In this case, those variables will be available for that\nnode and all children. This is useful for composition by allowing the same struct to be reused.\n\nWhen interpolating into flag or argument help strings, some extra variables\nare defined from the value itself:\n\n    ${default}\n    ${enum}\n\nFor flags with associated environment variables, the variable `${env}` can be\ninterpolated into the help string. In the absence of this variable in the\nhelp string, Kong will append `($$${env})` to the help string.\n\neg.\n\n```go\ntype cli struct {\n  Config string `type:\"path\" default:\"${config_file}\"`\n}\n\nfunc main() {\n  kong.Parse(\u0026cli,\n    kong.Vars{\n      \"config_file\": \"~/.app.conf\",\n    })\n}\n```\n\n## Validation\n\nKong does validation on the structure of a command-line, but also supports\nextensible validation. Any node in the tree may implement the following\ninterface:\n\n```go\ntype Validatable interface {\n    Validate() error\n }\n ```\n\n+If one of these nodes is in the active command-line it will be called during\n+normal validation.\n\n## Modifying Kong's behaviour\n\nEach Kong parser can be configured via functional options passed to `New(cli interface{}, options...Option)`.\n\nThe full set of options can be found [here](https://godoc.org/github.com/alecthomas/kong#Option).\n\n### `Name(help)` and `Description(help)` - set the application name description\n\nSet the application name and/or description.\n\nThe name of the application will default to the binary name, but can be overridden with `Name(name)`.\n\nAs with all help in Kong, text will be wrapped to the terminal.\n\n### `Configuration(loader, paths...)` - load defaults from configuration files\n\nThis option provides Kong with support for loading defaults from a set of configuration files. Each file is opened, if possible, and the loader called to create a resolver for that file.\n\neg.\n\n```go\nkong.Parse(\u0026cli, kong.Configuration(kong.JSON, \"/etc/myapp.json\", \"~/.myapp.json\"))\n```\n\n[See the tests](https://github.com/alecthomas/kong/blob/master/resolver_test.go#L103) for an example of how the JSON file is structured.\n\n### `Resolver(...)` - support for default values from external sources\n\nResolvers are Kong's extension point for providing default values from external sources. As an example, support for environment variables via the `env` tag is provided by a resolver. There's also a builtin resolver for JSON configuration files.\n\nExample resolvers can be found in [resolver.go](https://github.com/alecthomas/kong/blob/master/resolver.go).\n\n### `*Mapper(...)` - customising how the command-line is mapped to Go values\n\nCommand-line arguments are mapped to Go values via the Mapper interface:\n\n```go\n// A Mapper knows how to map command-line input to Go.\ntype Mapper interface {\n  // Decode scan into target.\n  //\n  // \"ctx\" contains context about the value being decoded that may be useful\n  // to some mappers.\n  Decode(ctx *MapperContext, scan *Scanner, target reflect.Value) error\n}\n```\n\nAll builtin Go types (as well as a bunch of useful stdlib types like `time.Time`) have mappers registered by default. Mappers for custom types can be added using `kong.??Mapper(...)` options. Mappers are applied to fields in four ways:\n\n1. `NamedMapper(string, Mapper)` and using the tag key `type:\"\u003cname\u003e\"`.\n2. `KindMapper(reflect.Kind, Mapper)`.\n3. `TypeMapper(reflect.Type, Mapper)`.\n4. `ValueMapper(interface{}, Mapper)`, passing in a pointer to a field of the grammar.\n\n### `ConfigureHelp(HelpOptions)` and `Help(HelpFunc)` - customising help\n\nThe default help output is usually sufficient, but if not there are two solutions.\n\n1. Use `ConfigureHelp(HelpOptions)` to configure how help is formatted (see [HelpOptions](https://godoc.org/github.com/alecthomas/kong#HelpOptions) for details).\n2. Custom help can be wired into Kong via the `Help(HelpFunc)` option. The `HelpFunc` is passed a `Context`, which contains the parsed context for the current command-line. See the implementation of `PrintHelp` for an example.\n3. Use `HelpFormatter(HelpValueFormatter)` if you want to just customize the help text that is accompanied by flags and arguments.\n4. Use `Groups([]Group)` if you want to customize group titles or add a header.\n\n### `Bind(...)` - bind values for callback hooks and Run() methods\n\nSee the [section on hooks](#hooks-beforeresolve-beforeapply-afterapply-and-the-bind-option) for details.\n\n### Other options\n\nThe full set of options can be found [here](https://godoc.org/github.com/alecthomas/kong#Option).\n","funding_links":["https://github.com/sponsors/alecthomas"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamdal%2Fkong","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamdal%2Fkong","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamdal%2Fkong/lists"}