{"id":37217537,"url":"https://github.com/euank/cobra","last_synced_at":"2026-01-15T01:01:45.802Z","repository":{"id":57603926,"uuid":"64794745","full_name":"euank/cobra","owner":"euank","description":"A Commander for modern Go CLI interactions","archived":false,"fork":true,"pushed_at":"2016-08-03T16:38:46.000Z","size":545,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T11:50:32.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"spf13/cobra","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euank.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-02T21:49:17.000Z","updated_at":"2016-08-02T21:49:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/euank/cobra","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/euank/cobra","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fcobra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fcobra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fcobra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fcobra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euank","download_url":"https://codeload.github.com/euank/cobra/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fcobra/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"ssl_error","status_checked_at":"2026-01-15T00:55:20.945Z","response_time":107,"last_error":"SSL_read: 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-15T01:01:44.257Z","updated_at":"2026-01-15T01:01:45.624Z","avatar_url":"https://github.com/euank.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![cobra logo](https://cloud.githubusercontent.com/assets/173412/10886352/ad566232-814f-11e5-9cd0-aa101788c117.png)\n\nCobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.\n\nMany of the most widely used Go projects are built using Cobra including:\n\n* [Kubernetes](http://kubernetes.io/)\n* [Hugo](http://gohugo.io)\n* [rkt](https://github.com/coreos/rkt)\n* [etcd](https://github.com/coreos/etcd)\n* [Docker (distribution)](https://github.com/docker/distribution)\n* [OpenShift](https://www.openshift.com/)\n* [Delve](https://github.com/derekparker/delve)\n* [GopherJS](http://www.gopherjs.org/)\n* [CockroachDB](http://www.cockroachlabs.com/)\n* [Bleve](http://www.blevesearch.com/)\n* [ProjectAtomic (enterprise)](http://www.projectatomic.io/)\n* [Parse (CLI)](https://parse.com/)\n* [GiantSwarm's swarm](https://github.com/giantswarm/cli)\n* [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack)\n\n\n[![Build Status](https://travis-ci.org/spf13/cobra.svg \"Travis CI status\")](https://travis-ci.org/spf13/cobra)\n[![CircleCI status](https://circleci.com/gh/spf13/cobra.png?circle-token=:circle-token \"CircleCI status\")](https://circleci.com/gh/spf13/cobra)\n[![GoDoc](https://godoc.org/github.com/spf13/cobra?status.svg)](https://godoc.org/github.com/spf13/cobra) \n\n![cobra](https://cloud.githubusercontent.com/assets/173412/10911369/84832a8e-8212-11e5-9f82-cc96660a4794.gif)\n\n# Overview\n\nCobra is a library providing a simple interface to create powerful modern CLI\ninterfaces similar to git \u0026 go tools.\n\nCobra is also an application that will generate your application scaffolding to rapidly\ndevelop a Cobra-based application.\n\nCobra provides:\n* Easy subcommand-based CLIs: `app server`, `app fetch`, etc.\n* Fully POSIX-compliant flags (including short \u0026 long versions)\n* Nested subcommands\n* Global, local and cascading flags\n* Easy generation of applications \u0026 commands with `cobra create appname` \u0026 `cobra add cmdname`\n* Intelligent suggestions (`app srver`... did you mean `app server`?)\n* Automatic help generation for commands and flags\n* Automatic detailed help for `app help [command]`\n* Automatic help flag recognition of `-h`, `--help`, etc.\n* Automatically generated bash autocomplete for your application\n* Automatically generated man pages for your application\n* Command aliases so you can change things without breaking them\n* The flexibilty to define your own help, usage, etc.\n* Optional tight integration with [viper](http://github.com/spf13/viper) for 12-factor apps\n\nCobra has an exceptionally clean interface and simple design without needless\nconstructors or initialization methods.\n\nApplications built with Cobra commands are designed to be as user-friendly as\npossible. Flags can be placed before or after the command (as long as a\nconfusing space isn’t provided). Both short and long flags can be used. A\ncommand need not even be fully typed.  Help is automatically generated and\navailable for the application or for a specific command using either the help\ncommand or the `--help` flag.\n\n# Concepts\n\nCobra is built on a structure of commands, arguments \u0026 flags.\n\n**Commands** represent actions, **Args** are things and **Flags** are modifiers for those actions.\n\nThe best applications will read like sentences when used. Users will know how\nto use the application because they will natively understand how to use it.\n\nThe pattern to follow is\n`APPNAME VERB NOUN --ADJECTIVE.`\n    or\n`APPNAME COMMAND ARG --FLAG`\n\nA few good real world examples may better illustrate this point.\n\nIn the following example, 'server' is a command, and 'port' is a flag:\n\n    \u003e hugo server --port=1313\n\nIn this command we are telling Git to clone the url bare.\n\n    \u003e git clone URL --bare\n\n## Commands\n\nCommand is the central point of the application. Each interaction that\nthe application supports will be contained in a Command. A command can\nhave children commands and optionally run an action.\n\nIn the example above, 'server' is the command.\n\nA Command has the following structure:\n\n```go\ntype Command struct {\n    Use string // The one-line usage message.\n    Short string // The short description shown in the 'help' output.\n    Long string // The long message shown in the 'help \u003cthis-command\u003e' output.\n    Run func(cmd *Command, args []string) // Run runs the command.\n}\n```\n\n## Flags\n\nA Flag is a way to modify the behavior of a command. Cobra supports\nfully POSIX-compliant flags as well as the Go [flag package](https://golang.org/pkg/flag/).\nA Cobra command can define flags that persist through to children commands\nand flags that are only available to that command.\n\nIn the example above, 'port' is the flag.\n\nFlag functionality is provided by the [pflag\nlibrary](https://github.com/ogier/pflag), a fork of the flag standard library\nwhich maintains the same interface while adding POSIX compliance.\n\n## Usage\n\nCobra works by creating a set of commands and then organizing them into a tree.\nThe tree defines the structure of the application.\n\nOnce each command is defined with its corresponding flags, then the\ntree is assigned to the commander which is finally executed.\n\n# Installing\nUsing Cobra is easy. First, use `go get` to install the latest version\nof the library. This command will install the `cobra` generator executible\nalong with the library:\n\n    \u003e go get -v github.com/spf13/cobra/cobra\n\nNext, include Cobra in your application:\n\n```go\nimport \"github.com/spf13/cobra\"\n```\n\n# Getting Started\n\nWhile you are welcome to provide your own organization, typically a Cobra based\napplication will follow the following organizational structure.\n\n```\n  ▾ appName/\n    ▾ cmd/\n        add.go\n        your.go\n        commands.go\n        here.go\n      main.go\n```\n\nIn a Cobra app, typically the main.go file is very bare. It serves, one purpose, to initialize Cobra.\n\n```go\npackage main\n\nimport \"{pathToYourApp}/cmd\"\n\nfunc main() {\n\tif err := cmd.RootCmd.Execute(); err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(-1)\n\t}\n}\n```\n\n## Using the Cobra Generator\n\nCobra provides its own program that will create your application and add any\ncommands you want. It's the easiest way to incorporate Cobra into your application.\n\nIn order to use the cobra command, compile it using the following command:\n\n    \u003e go install github.com/spf13/cobra/cobra\n\nThis will create the cobra executable under your go path bin directory!\n\n### cobra init\n\nThe `cobra init [yourApp]` command will create your initial application code\nfor you. It is a very powerful application that will populate your program with\nthe right structure so you can immediately enjoy all the benefits of Cobra. It\nwill also automatically apply the license you specify to your application.\n\nCobra init is pretty smart. You can provide it a full path, or simply a path\nsimilar to what is expected in the import.\n\n```\ncobra init github.com/spf13/newAppName\n```\n\n### cobra add\n\nOnce an application is initialized Cobra can create additional commands for you.\nLet's say you created an app and you wanted the following commands for it:\n\n* app serve\n* app config\n* app config create\n\nIn your project directory (where your main.go file is) you would run the following:\n\n```\ncobra add serve\ncobra add config\ncobra add create -p 'configCmd'\n```\n\nOnce you have run these three commands you would have an app structure that would look like:\n\n```\n  ▾ app/\n    ▾ cmd/\n        serve.go\n        config.go\n        create.go\n      main.go\n```\n\nat this point you can run `go run main.go` and it would run your app. `go run\nmain.go serve`, `go run main.go config`, `go run main.go config create` along\nwith `go run main.go help serve`, etc would all work.\n\nObviously you haven't added your own code to these yet, the commands are ready\nfor you to give them their tasks. Have fun.\n\n### Configuring the cobra generator\n\nThe cobra generator will be easier to use if you provide a simple configuration\nfile which will help you eliminate providing a bunch of repeated information in\nflags over and over.\n\nAn example ~/.cobra.yaml file:\n\n```yaml\nauthor: Steve Francia \u003cspf@spf13.com\u003e\nlicense: MIT\n```\n\nYou can specify no license by setting `license` to `none` or you can specify\na custom license:\n\n```yaml\nlicense:\n  header: This file is part of {{ .appName }}.\n  text: |\n    {{ .copyright }}\n\n    This is my license. There are many like it, but this one is mine.\n    My license is my best friend. It is my life. I must master it as I must\n    master my life.  \n```\n\n## Manually implementing Cobra\n\nTo manually implement cobra you need to create a bare main.go file and a RootCmd file.\nYou will optionally provide additional commands as you see fit.\n\n### Create the root command\n\nThe root command represents your binary itself.\n\n\n#### Manually create rootCmd\n\nCobra doesn't require any special constructors. Simply create your commands.\n\nIdeally you place this in app/cmd/root.go:\n\n```go\nvar RootCmd = \u0026cobra.Command{\n\tUse:   \"hugo\",\n\tShort: \"Hugo is a very fast static site generator\",\n\tLong: `A Fast and Flexible Static Site Generator built with\n                love by spf13 and friends in Go.\n                Complete documentation is available at http://hugo.spf13.com`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\t// Do Stuff Here\n\t},\n}\n```\n\nYou will additionally define flags and handle configuration in your init() function.\n\nfor example cmd/root.go:\n\n```go\nfunc init() {\n\tcobra.OnInitialize(initConfig)\n\tRootCmd.PersistentFlags().StringVar(\u0026cfgFile, \"config\", \"\", \"config file (default is $HOME/.cobra.yaml)\")\n\tRootCmd.PersistentFlags().StringVarP(\u0026projectBase, \"projectbase\", \"b\", \"\", \"base project directory eg. github.com/spf13/\")\n\tRootCmd.PersistentFlags().StringP(\"author\", \"a\", \"YOUR NAME\", \"Author name for copyright attribution\")\n\tRootCmd.PersistentFlags().StringVarP(\u0026userLicense, \"license\", \"l\", \"\", \"Name of license for the project (can provide `licensetext` in config)\")\n\tRootCmd.PersistentFlags().Bool(\"viper\", true, \"Use Viper for configuration\")\n\tviper.BindPFlag(\"author\", RootCmd.PersistentFlags().Lookup(\"author\"))\n\tviper.BindPFlag(\"projectbase\", RootCmd.PersistentFlags().Lookup(\"projectbase\"))\n\tviper.BindPFlag(\"useViper\", RootCmd.PersistentFlags().Lookup(\"viper\"))\n\tviper.SetDefault(\"author\", \"NAME HERE \u003cEMAIL ADDRESS\u003e\")\n\tviper.SetDefault(\"license\", \"apache\")\n}\n```\n\n### Create your main.go\n\nWith the root command you need to have your main function execute it.\nExecute should be run on the root for clarity, though it can be called on any command.\n\nIn a Cobra app, typically the main.go file is very bare. It serves, one purpose, to initialize Cobra.\n\n```go\npackage main\n\nimport \"{pathToYourApp}/cmd\"\n\nfunc main() {\n\tif err := cmd.RootCmd.Execute(); err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(-1)\n\t}\n}\n```\n\n\n### Create additional commands\n\nAdditional commands can be defined and typically are each given their own file\ninside of the cmd/ directory.\n\nIf you wanted to create a version command you would create cmd/version.go and\npopulate it with the following:\n\n```go\npackage cmd\n\nimport (\n\t\"github.com/spf13/cobra\"\n)\n\nfunc init() {\n\tRootCmd.AddCommand(versionCmd)\n}\n\nvar versionCmd = \u0026cobra.Command{\n\tUse:   \"version\",\n\tShort: \"Print the version number of Hugo\",\n\tLong:  `All software has versions. This is Hugo's`,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tfmt.Println(\"Hugo Static Site Generator v0.9 -- HEAD\")\n\t},\n}\n```\n\n### Attach command to its parent\n\n\nIf you notice in the above example we attach the command to its parent. In\nthis case the parent is the rootCmd. In this example we are attaching it to the\nroot, but commands can be attached at any level.\n\n```go\nRootCmd.AddCommand(versionCmd)\n```\n\n### Remove a command from its parent\n\nRemoving a command is not a common action in simple programs, but it allows 3rd\nparties to customize an existing command tree.\n\nIn this example, we remove the existing `VersionCmd` command of an existing\nroot command, and we replace it with our own version:\n\n```go\nmainlib.RootCmd.RemoveCommand(mainlib.VersionCmd)\nmainlib.RootCmd.AddCommand(versionCmd)\n```\n\n## Working with Flags\n\nFlags provide modifiers to control how the action command operates.\n\n### Assign flags to a command\n\nSince the flags are defined and used in different locations, we need to\ndefine a variable outside with the correct scope to assign the flag to\nwork with.\n\n```go\nvar Verbose bool\nvar Source string\n```\n\nThere are two different approaches to assign a flag.\n\n### Persistent Flags\n\nA flag can be 'persistent' meaning that this flag will be available to the\ncommand it's assigned to as well as every command under that command. For\nglobal flags, assign a flag as a persistent flag on the root.\n\n```go\nRootCmd.PersistentFlags().BoolVarP(\u0026Verbose, \"verbose\", \"v\", false, \"verbose output\")\n```\n\n### Local Flags\n\nA flag can also be assigned locally which will only apply to that specific command.\n\n```go\nRootCmd.Flags().StringVarP(\u0026Source, \"source\", \"s\", \"\", \"Source directory to read from\")\n```\n\n\n## Example\n\nIn the example below, we have defined three commands. Two are at the top level\nand one (cmdTimes) is a child of one of the top commands. In this case the root\nis not executable meaning that a subcommand is required. This is accomplished\nby not providing a 'Run' for the 'rootCmd'.\n\nWe have only defined one flag for a single command.\n\nMore documentation about flags is available at https://github.com/spf13/pflag\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nfunc main() {\n\n\tvar echoTimes int\n\n\tvar cmdPrint = \u0026cobra.Command{\n\t\tUse:   \"print [string to print]\",\n\t\tShort: \"Print anything to the screen\",\n\t\tLong: `print is for printing anything back to the screen.\n            For many years people have printed back to the screen.\n            `,\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Println(\"Print: \" + strings.Join(args, \" \"))\n\t\t},\n\t}\n\n\tvar cmdEcho = \u0026cobra.Command{\n\t\tUse:   \"echo [string to echo]\",\n\t\tShort: \"Echo anything to the screen\",\n\t\tLong: `echo is for echoing anything back.\n            Echo works a lot like print, except it has a child command.\n            `,\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Println(\"Print: \" + strings.Join(args, \" \"))\n\t\t},\n\t}\n\n\tvar cmdTimes = \u0026cobra.Command{\n\t\tUse:   \"times [# times] [string to echo]\",\n\t\tShort: \"Echo anything to the screen more times\",\n\t\tLong: `echo things multiple times back to the user by providing\n            a count and a string.`,\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfor i := 0; i \u003c echoTimes; i++ {\n\t\t\t\tfmt.Println(\"Echo: \" + strings.Join(args, \" \"))\n\t\t\t}\n\t\t},\n\t}\n\n\tcmdTimes.Flags().IntVarP(\u0026echoTimes, \"times\", \"t\", 1, \"times to echo the input\")\n\n\tvar rootCmd = \u0026cobra.Command{Use: \"app\"}\n\trootCmd.AddCommand(cmdPrint, cmdEcho)\n\tcmdEcho.AddCommand(cmdTimes)\n\trootCmd.Execute()\n}\n```\n\nFor a more complete example of a larger application, please checkout [Hugo](http://gohugo.io/).\n\n## The Help Command\n\nCobra automatically adds a help command to your application when you have subcommands.\nThis will be called when a user runs 'app help'. Additionally, help will also\nsupport all other commands as input. Say, for instance, you have a command called\n'create' without any additional configuration; Cobra will work when 'app help\ncreate' is called.  Every command will automatically have the '--help' flag added.\n\n### Example\n\nThe following output is automatically generated by Cobra. Nothing beyond the\ncommand and flag definitions are needed.\n\n    \u003e hugo help\n\n    hugo is the main command, used to build your Hugo site.\n\n    Hugo is a Fast and Flexible Static Site Generator\n    built with love by spf13 and friends in Go.\n\n    Complete documentation is available at http://gohugo.io/.\n\n    Usage:\n      hugo [flags]\n      hugo [command]\n\n    Available Commands:\n      server          Hugo runs its own webserver to render the files\n      version         Print the version number of Hugo\n      config          Print the site configuration\n      check           Check content in the source directory\n      benchmark       Benchmark hugo by building a site a number of times.\n      convert         Convert your content to different formats\n      new             Create new content for your site\n      list            Listing out various types of content\n      undraft         Undraft changes the content's draft status from 'True' to 'False'\n      genautocomplete Generate shell autocompletion script for Hugo\n      gendoc          Generate Markdown documentation for the Hugo CLI.\n      genman          Generate man page for Hugo\n      import          Import your site from others.\n\n    Flags:\n      -b, --baseURL=\"\": hostname (and path) to the root, e.g. http://spf13.com/\n      -D, --buildDrafts[=false]: include content marked as draft\n      -F, --buildFuture[=false]: include content with publishdate in the future\n          --cacheDir=\"\": filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/\n          --canonifyURLs[=false]: if true, all relative URLs will be canonicalized using baseURL\n          --config=\"\": config file (default is path/config.yaml|json|toml)\n      -d, --destination=\"\": filesystem path to write files to\n          --disableRSS[=false]: Do not build RSS files\n          --disableSitemap[=false]: Do not build Sitemap file\n          --editor=\"\": edit new content with this editor, if provided\n          --ignoreCache[=false]: Ignores the cache directory for reading but still writes to it\n          --log[=false]: Enable Logging\n          --logFile=\"\": Log File path (if set, logging enabled automatically)\n          --noTimes[=false]: Don't sync modification time of files\n          --pluralizeListTitles[=true]: Pluralize titles in lists using inflect\n          --preserveTaxonomyNames[=false]: Preserve taxonomy names as written (\"Gérard Depardieu\" vs \"gerard-depardieu\")\n      -s, --source=\"\": filesystem path to read files relative from\n          --stepAnalysis[=false]: display memory and timing of different steps of the program\n      -t, --theme=\"\": theme to use (located in /themes/THEMENAME/)\n          --uglyURLs[=false]: if true, use /filename.html instead of /filename/\n      -v, --verbose[=false]: verbose output\n          --verboseLog[=false]: verbose logging\n      -w, --watch[=false]: watch filesystem for changes and recreate as needed\n\n    Use \"hugo [command] --help\" for more information about a command.\n\n\nHelp is just a command like any other. There is no special logic or behavior\naround it. In fact, you can provide your own if you want.\n\n### Defining your own help\n\nYou can provide your own Help command or your own template for the default command to use.\n\nThe default help command is\n\n```go\nfunc (c *Command) initHelp() {\n\tif c.helpCommand == nil {\n\t\tc.helpCommand = \u0026Command{\n\t\t\tUse:   \"help [command]\",\n\t\t\tShort: \"Help about any command\",\n\t\t\tLong: `Help provides help for any command in the application.\n        Simply type ` + c.Name() + ` help [path to command] for full details.`,\n\t\t\tRun: c.HelpFunc(),\n\t\t}\n\t}\n\tc.AddCommand(c.helpCommand)\n}\n```\n\nYou can provide your own command, function or template through the following methods:\n\n```go\ncommand.SetHelpCommand(cmd *Command)\n\ncommand.SetHelpFunc(f func(*Command, []string))\n\ncommand.SetHelpTemplate(s string)\n```\n\nThe latter two will also apply to any children commands.\n\n## Usage\n\nWhen the user provides an invalid flag or invalid command, Cobra responds by\nshowing the user the 'usage'.\n\n### Example\nYou may recognize this from the help above. That's because the default help\nembeds the usage as part of its output.\n\n    Usage:\n      hugo [flags]\n      hugo [command]\n\n    Available Commands:\n      server          Hugo runs its own webserver to render the files\n      version         Print the version number of Hugo\n      config          Print the site configuration\n      check           Check content in the source directory\n      benchmark       Benchmark hugo by building a site a number of times.\n      convert         Convert your content to different formats\n      new             Create new content for your site\n      list            Listing out various types of content\n      undraft         Undraft changes the content's draft status from 'True' to 'False'\n      genautocomplete Generate shell autocompletion script for Hugo\n      gendoc          Generate Markdown documentation for the Hugo CLI.\n      genman          Generate man page for Hugo\n      import          Import your site from others.\n\n    Flags:\n      -b, --baseURL=\"\": hostname (and path) to the root, e.g. http://spf13.com/\n      -D, --buildDrafts[=false]: include content marked as draft\n      -F, --buildFuture[=false]: include content with publishdate in the future\n          --cacheDir=\"\": filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/\n          --canonifyURLs[=false]: if true, all relative URLs will be canonicalized using baseURL\n          --config=\"\": config file (default is path/config.yaml|json|toml)\n      -d, --destination=\"\": filesystem path to write files to\n          --disableRSS[=false]: Do not build RSS files\n          --disableSitemap[=false]: Do not build Sitemap file\n          --editor=\"\": edit new content with this editor, if provided\n          --ignoreCache[=false]: Ignores the cache directory for reading but still writes to it\n          --log[=false]: Enable Logging\n          --logFile=\"\": Log File path (if set, logging enabled automatically)\n          --noTimes[=false]: Don't sync modification time of files\n          --pluralizeListTitles[=true]: Pluralize titles in lists using inflect\n          --preserveTaxonomyNames[=false]: Preserve taxonomy names as written (\"Gérard Depardieu\" vs \"gerard-depardieu\")\n      -s, --source=\"\": filesystem path to read files relative from\n          --stepAnalysis[=false]: display memory and timing of different steps of the program\n      -t, --theme=\"\": theme to use (located in /themes/THEMENAME/)\n          --uglyURLs[=false]: if true, use /filename.html instead of /filename/\n      -v, --verbose[=false]: verbose output\n          --verboseLog[=false]: verbose logging\n      -w, --watch[=false]: watch filesystem for changes and recreate as needed\n\n### Defining your own usage\nYou can provide your own usage function or template for Cobra to use.\n\nThe default usage function is:\n\n```go\nreturn func(c *Command) error {\n\terr := tmpl(c.Out(), c.UsageTemplate(), c)\n\treturn err\n}\n```\n\nLike help, the function and template are overridable through public methods:\n\n```go\ncommand.SetUsageFunc(f func(*Command) error)\n\ncommand.SetUsageTemplate(s string)\n```\n\n## PreRun or PostRun Hooks\n\nIt is possible to run functions before or after the main `Run` function of your command. The `PersistentPreRun` and `PreRun` functions will be executed before `Run`. `PersistentPostRun` and `PostRun` will be executed after `Run`.  The `Persistent*Run` functions will be inherrited by children if they do not declare their own.  These function are run in the following order:\n\n- `PersistentPreRun`\n- `PreRun`\n- `Run`\n- `PostRun`\n- `PersistentPostRun`\n\nAn example of two commands which use all of these features is below.  When the subcommand is executed, it will run the root command's `PersistentPreRun` but not the root command's `PersistentPostRun`:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nfunc main() {\n\n\tvar rootCmd = \u0026cobra.Command{\n\t\tUse:   \"root [sub]\",\n\t\tShort: \"My root command\",\n\t\tPersistentPreRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside rootCmd PersistentPreRun with args: %v\\n\", args)\n\t\t},\n\t\tPreRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside rootCmd PreRun with args: %v\\n\", args)\n\t\t},\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside rootCmd Run with args: %v\\n\", args)\n\t\t},\n\t\tPostRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside rootCmd PostRun with args: %v\\n\", args)\n\t\t},\n\t\tPersistentPostRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside rootCmd PersistentPostRun with args: %v\\n\", args)\n\t\t},\n\t}\n\n\tvar subCmd = \u0026cobra.Command{\n\t\tUse:   \"sub [no options!]\",\n\t\tShort: \"My subcommand\",\n\t\tPreRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside subCmd PreRun with args: %v\\n\", args)\n\t\t},\n\t\tRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside subCmd Run with args: %v\\n\", args)\n\t\t},\n\t\tPostRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside subCmd PostRun with args: %v\\n\", args)\n\t\t},\n\t\tPersistentPostRun: func(cmd *cobra.Command, args []string) {\n\t\t\tfmt.Printf(\"Inside subCmd PersistentPostRun with args: %v\\n\", args)\n\t\t},\n\t}\n\n\trootCmd.AddCommand(subCmd)\n\n\trootCmd.SetArgs([]string{\"\"})\n\t_ = rootCmd.Execute()\n\tfmt.Print(\"\\n\")\n\trootCmd.SetArgs([]string{\"sub\", \"arg1\", \"arg2\"})\n\t_ = rootCmd.Execute()\n}\n```\n\n\n## Alternative Error Handling\n\nCobra also has functions where the return signature is an error. This allows for errors to bubble up to the top,\nproviding a way to handle the errors in one location. The current list of functions that return an error is:\n\n* PersistentPreRunE\n* PreRunE\n* RunE\n* PostRunE\n* PersistentPostRunE\n\nIf you would like to silence the default `error` and `usage` output in favor of your own, you can set `SilenceUsage`\nand `SilenceErrors` to `false` on the command. A child command respects these flags if they are set on the parent\ncommand.\n\n**Example Usage using RunE:**\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"log\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nfunc main() {\n\tvar rootCmd = \u0026cobra.Command{\n\t\tUse:   \"hugo\",\n\t\tShort: \"Hugo is a very fast static site generator\",\n\t\tLong: `A Fast and Flexible Static Site Generator built with\n                love by spf13 and friends in Go.\n                Complete documentation is available at http://hugo.spf13.com`,\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\t// Do Stuff Here\n\t\t\treturn errors.New(\"some random error\")\n\t\t},\n\t}\n\n\tif err := rootCmd.Execute(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n## Suggestions when \"unknown command\" happens\n\nCobra will print automatic suggestions when \"unknown command\" errors happen. This allows Cobra to behave similarly to the `git` command when a typo happens. For example:\n\n```\n$ hugo srever\nError: unknown command \"srever\" for \"hugo\"\n\nDid you mean this?\n        server\n\nRun 'hugo --help' for usage.\n```\n\nSuggestions are automatic based on every subcommand registered and use an implementation of [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.\n\nIf you need to disable suggestions or tweak the string distance in your command, use:\n\n```go\ncommand.DisableSuggestions = true\n```\n\nor\n\n```go\ncommand.SuggestionsMinimumDistance = 1\n```\n\nYou can also explicitly set names for which a given command will be suggested using the `SuggestFor` attribute. This allows suggestions for strings that are not close in terms of string distance, but makes sense in your set of commands and for some which you don't want aliases. Example:\n\n```\n$ kubectl remove\nError: unknown command \"remove\" for \"kubectl\"\n\nDid you mean this?\n        delete\n\nRun 'kubectl help' for usage.\n```\n\n## Generating Markdown-formatted documentation for your command\n\nCobra can generate a Markdown-formatted document based on the subcommands, flags, etc. A simple example of how to do this for your command can be found in [Markdown Docs](doc/md_docs.md).\n\n## Generating man pages for your command\n\nCobra can generate a man page based on the subcommands, flags, etc. A simple example of how to do this for your command can be found in [Man Docs](doc/man_docs.md).\n\n## Generating bash completions for your command\n\nCobra can generate a bash-completion file. If you add more information to your command, these completions can be amazingly powerful and flexible.  Read more about it in [Bash Completions](bash_completions.md).\n\n## Debugging\n\nCobra provides a ‘DebugFlags’ method on a command which, when called, will print\nout everything Cobra knows about the flags for each command.\n\n### Example\n\n```go\ncommand.DebugFlags()\n```\n\n## Release Notes\n* **0.9.0** June 17, 2014\n  * flags can appears anywhere in the args (provided they are unambiguous)\n  * --help prints usage screen for app or command\n  * Prefix matching for commands\n  * Cleaner looking help and usage output\n  * Extensive test suite\n* **0.8.0** Nov 5, 2013\n  * Reworked interface to remove commander completely\n  * Command now primary structure\n  * No initialization needed\n  * Usage \u0026 Help templates \u0026 functions definable at any level\n  * Updated Readme\n* **0.7.0** Sept 24, 2013\n  * Needs more eyes\n  * Test suite\n  * Support for automatic error messages\n  * Support for help command\n  * Support for printing to any io.Writer instead of os.Stderr\n  * Support for persistent flags which cascade down tree\n  * Ready for integration into Hugo\n* **0.1.0** Sept 3, 2013\n  * Implement first draft\n\n## Extensions\n\nLibraries for extending Cobra:\n\n* [cmdns](https://github.com/gosuri/cmdns): Enables name spacing a command's immediate children. It provides an alternative way to structure subcommands, similar to `heroku apps:create` and `ovrclk clusters:launch`.\n\n## ToDo\n* Launch proper documentation site\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Contributors\n\nNames in no particular order:\n\n* [spf13](https://github.com/spf13),\n[eparis](https://github.com/eparis),\n[bep](https://github.com/bep), and many more!\n\n## License\n\nCobra is released under the Apache 2.0 license. See [LICENSE.txt](https://github.com/spf13/cobra/blob/master/LICENSE.txt)\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/spf13/cobra/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fcobra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feuank%2Fcobra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fcobra/lists"}