{"id":34588686,"url":"https://github.com/alexrsagen/go-cli","last_synced_at":"2026-05-30T05:31:12.267Z","repository":{"id":141243419,"uuid":"132821531","full_name":"alexrsagen/go-cli","owner":"alexrsagen","description":"A command-line interface library written in Go","archived":false,"fork":false,"pushed_at":"2018-06-12T18:03:13.000Z","size":79,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T16:39:06.510Z","etag":null,"topics":["cli","command-line-parser","commandline-interface","go","golang","termbox-go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexrsagen.png","metadata":{"files":{"readme":"README.md","changelog":"history.go","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":"2018-05-09T23:03:00.000Z","updated_at":"2019-01-22T23:33:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"a844e00d-61d3-47f2-945e-a193467096d9","html_url":"https://github.com/alexrsagen/go-cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexrsagen/go-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fgo-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fgo-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fgo-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fgo-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexrsagen","download_url":"https://codeload.github.com/alexrsagen/go-cli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fgo-cli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33681809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cli","command-line-parser","commandline-interface","go","golang","termbox-go"],"created_at":"2025-12-24T10:48:04.114Z","updated_at":"2026-05-30T05:31:12.260Z","avatar_url":"https://github.com/alexrsagen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-cli\nA simple CLI library written in Go.\n\nThe library is intended to be used for a whole application, meaning only one CLI is possible for the whole app.\n\n![Demo GIF](https://raw.githubusercontent.com/alexrsagen/go-cli/master/demo.gif)\n\n## Features\n- Command autocompletion\n- Bash-like command history\n- Easy to use!\n\n## Usage\n```go\nimport \"github.com/alexrsagen/go-cli\"\n```\n\nGet started by taking a look at the example usage in [Exec](#exec).\n\n### CommandList\n```go\ntype CommandList map[string]*Command\n```\n\nThis is a collection of commands stored by name.\n\nExample command list:\n```go\nvar list cli.CommandList\nlist = cli.CommandList{\n    \"command\": \u0026cli.Command{\n        Description: \"Example command\",\n        Handler: func(args []string) {\n            cli.Println(\"Example command ran!\")\n        },\n    },\n    \"submenu\": \u0026cli.Command{\n        Description: \"A nested menu of commands\",\n        Handler: func(args []string) {\n            cli.SetList(list[\"submenu\"].List)\n            cli.SetPrefix(\"my-cli(submenu)# \")\n        },\n        List: cli.CommandList{\n            \"command\": \u0026cli.Command{\n                Description: \"Example command\",\n                Handler: func(args []string) {\n                    cli.Println(\"Submenu example command ran!\")\n                },\n            },\n            \"return\": \u0026cli.Command{\n                Description: \"Return from submenu context\",\n                Handler: func(args []string) {\n                    cli.SetList(list)\n                    cli.SetPrefix(\"my-cli# \")\n                },\n            },\n        },\n    },\n    \"another_submenu\": \u0026cli.Command{\n        Description: \"Another nested menu of commands\",\n        Handler: func(args []string) {\n            cli.SetList(list[\"submenu\"].List)\n            cli.SetPrefix(\"my-cli(submenu)# \")\n        },\n        List: cli.CommandList{\n            \"command\": \u0026cli.Command{\n                Description: \"Example command\",\n                Handler: func(args []string) {\n                    cli.Println(\"Another submenu example command ran!\")\n                },\n            },\n            \"return\": \u0026cli.Command{\n                Description: \"Return from submenu context\",\n                Handler: func(args []string) {\n                    cli.SetList(list)\n                    cli.SetPrefix(\"my-cli# \")\n                },\n            },\n        },\n    },\n}\n```\n\n### CommandHandler\n```go\ntype CommandHandler func(args []string)\n```\nThis defines the prototype for a function ran when executing a [Command](#command)\n\n### Command\n```go\ntype Command struct {\n    Description string\n    Arguments   []string\n    Handler     CommandHandler\n    List        CommandList\n}\n```\n\nThis is a structure for storing a single command item. You cannot store the name of a command inside itself. Use a [CommandList](#commandlist) to store commands by name.\n\nA [Command](#command) containing other commands may not have a handler set. **If you do this, it will result in a runtime panic.**\n\nExample command item:\n```go\nvar item *cli.Command\nitem = \u0026cli.Command{\n    Description: \"Example command\",\n    Handler: func(args []string) {\n        cli.Println(\"Example command ran!\")\n    },\n}\n```\n\n### Exec\n```go\nfunc Exec(path []string) bool\n```\n\nThis function attempts to execute a single command, and returns true if the command executed.\n\nExample usage:\n```go\nimport \"os\"\nimport \"github.com/alexrsagen/go-cli\"\n\nfunc main() {\n    cli.SetList(cli.CommandList{\n        \"command\": \u0026cli.Command{\n            Description: \"Example command\",\n            Handler: func(args []string) {\n                cli.Println(\"Example command ran!\")\n            },\n        }\n    })\n\n    // Default prefix is \"# \", but you can change it like so:\n    // cli.SetPrefix(\"my-cli# \")\n\n    // Executes a command directly, if one is given in arguments.\n    // Otherwise creates a CLI.\n    if len(os.Args) \u003e 1 {\n        if !cli.Exec(os.Args[1:]) {\n            os.Exit(1)\n        }\n    } else {\n        err := cli.Run()\n        if err != nil {\n            panic(err) // Received an error event from termbox\n        }\n    }\n}\n```\n\n### Field\n```go\ntype Field struct {\n\tDisplayName, Input string\n\tMask               rune\n\tFormat             *regexp.Regexp\n}\n```\n\nThis is a structure containing a single form field.\n\n### FieldCategory\n```go\ntype FieldCategory struct {\n\tDisplayName string\n\tFields      FieldList\n}\n```\n\nThis is a [FieldList](#fieldlist) with a title.\n\n### FieldList\n```go\ntype FieldList []*Field\n```\n\nThis is a collection of form fields.\n\n### FieldCategoryList\n```go\ntype FieldCategoryList []*FieldCategory\n```\n\nThis is a collection of field categories.\n\n### Form\n```go\nfunc (fl FieldList) Form() bool\nfunc (fcl FieldCategoryList) Form() bool\n```\n\nThese functions render a series of input fields to be filled before returning. Should be used within a [CommandHandler](#commandhandler). The FieldCategoryList `Form()` function also renders its category titles.\n\nThe return value is `false` if the input was cancelled or if inputs did not validate, otherwise `true`.\n\nExample usage:\n```go\nfunc myHandler(args []string) {\n    field1 := \u0026cli.Field{DisplayName: \"Field 1\"}\n    field2 := \u0026cli.Field{DisplayName: \"Field 2\"}\n    field3 := \u0026cli.Field{DisplayName: \"Field 3\"}\n    field4 := \u0026cli.Field{DisplayName: \"Field 4\"}\n    field5 := \u0026cli.Field{DisplayName: \"Field 5\"}\n    field6 := \u0026cli.Field{DisplayName: \"Field 6\"}\n    \n    fcl := cli.FieldCategoryList{\n        \u0026cli.FieldCategory{\n            DisplayName: \"Category 1\",\n            Fields: cli.FieldList{\n                field1,\n                field2,\n                field3,\n            },\n        },\n        \u0026cli.FieldCategory{\n            DisplayName: \"Category 2\",\n            Fields: cli.FieldList{\n                field4,\n                field5,\n                field6,\n            },\n        },\n    }\n    \n    fcl.Form()\n    \n    cli.Println(\"Form filled!\\n\")\n    cli.Printf(\"%s: %s\\n\", field1.DisplayName, field1.Input)\n    cli.Printf(\"%s: %s\\n\", field2.DisplayName, field2.Input)\n    cli.Printf(\"%s: %s\\n\", field3.DisplayName, field3.Input)\n    cli.Printf(\"%s: %s\\n\", field4.DisplayName, field4.Input)\n    cli.Printf(\"%s: %s\\n\", field5.DisplayName, field5.Input)\n    cli.Printf(\"%s: %s\\n\", field6.DisplayName, field6.Input)\n}\n```\n\n### SetPrefix\n```go\nfunc SetPrefix(s string)\n```\n\nThis function sets the CLI input prefix string.\n\nExample usage: see [Exec](#exec)\n\n### SetList\n```go\nfunc SetList(l CommandList)\n```\n\nThis function sets the CLI command list.\n\nExample usage: see [Exec](#exec)\n\n### Run\n```go\nfunc Run() error\n```\n\nThis function sets up a new CLI on the process tty.\n\nExample usage: see [Exec](#exec)\n\n### Printf\n```go\nfunc Printf(format string, a ...interface{})\n```\n\nA wrapper around [fmt.Sprintf](https://golang.org/pkg/fmt/#Sprintf).\n\nThe point of the wrapper function is to be able to correctly write the output to the terminal created by [termbox](https://github.com/nsf/termbox-go). Falls back to calling [fmt.Printf](https://golang.org/pkg/fmt/#Printf) directly when a terminal is has not been started.\n\n### Println\n```go\nfunc Println(a ...interface{})\n```\n\nA wrapper around [fmt.Sprintln](https://golang.org/pkg/fmt/#Sprintln).\n\nThe point of the wrapper function is to be able to correctly write the output to the terminal created by [termbox](https://github.com/nsf/termbox-go). Falls back to calling [fmt.Println](https://golang.org/pkg/fmt/#Println) directly when a terminal is has not been started.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrsagen%2Fgo-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexrsagen%2Fgo-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrsagen%2Fgo-cli/lists"}