{"id":18247009,"url":"https://github.com/osspkg/go-console","last_synced_at":"2025-07-23T19:04:51.377Z","repository":{"id":250588492,"uuid":"834871623","full_name":"osspkg/go-console","owner":"osspkg","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-28T21:53:29.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T19:35:32.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osspkg.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":"2024-07-28T16:05:24.000Z","updated_at":"2024-07-28T21:52:59.000Z","dependencies_parsed_at":"2024-11-05T09:30:23.987Z","dependency_job_id":"29d8d73c-48bc-4eb4-a79e-955120338cf9","html_url":"https://github.com/osspkg/go-console","commit_stats":null,"previous_names":["osspkg/go-console"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/osspkg/go-console","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osspkg%2Fgo-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osspkg%2Fgo-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osspkg%2Fgo-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osspkg%2Fgo-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osspkg","download_url":"https://codeload.github.com/osspkg/go-console/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osspkg%2Fgo-console/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266737719,"owners_count":23976392,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-11-05T09:28:34.524Z","updated_at":"2025-07-23T19:04:51.360Z","avatar_url":"https://github.com/osspkg.png","language":"Go","readme":"# Console application\n\n## Creating console application\n\n```go\nimport \"go.osspkg.com/console\"\n\n// creating an instance of the application, \n// specifying its name and description for flag: --help \nroot := console.New(\"tool\", \"help tool\")\n// adding root command\nroot.RootCommand(...)\n// adding one or more commands\nroot.AddCommand(...)\n// launching the app\nroot.Exec()\n```\n\n## Creating a simple command\n\n```go\nimport \"go.osspkg.com/x/console\"\n// creating a new team with settings\nconsole.NewCommand(func(setter console.CommandSetter) {\n\t// passing the command name and description\n    setter.Setup(\"simple\", \"first-level command\")\n    // description of the usage example\n    setter.Example(\"simple aa/bb/cc -a=hello -b=123 --cc=123.456 -e\")\n    // description of flags\n    setter.Flag(func(f console.FlagsSetter) {\n    \t// you can specify the flag's name, default value, and information about the flag's value.\n        f.StringVar(\"a\", \"demo\", \"this is a string argument\")\n        f.IntVar(\"b\", 1, \"this is a int64 argument\")\n        f.FloatVar(\"cc\", 1e-5, \"this is a float64 argument\")\n        f.Bool(\"d\", \"this is a bool argument\")\n    })\n    // argument validation: specifies the number of arguments, \n    // and validation function that should return \n    // value after validation and validation error\n    setter.ArgumentFunc(func(s []string) ([]string, error) {\n        if !strings.Contains(s[0], \"/\") {\n            return nil, fmt.Errorf(\"argument must contain /\")\n        }\n        return strings.Split(s[0], \"/\"), nil\n    })\n    // command execution function\n    // first argument is a slice of arguments from setter.Argument\n    // all subsequent arguments must be in the same order and types as listed in setter.Flag\n    setter.ExecFunc(func(args []string, a string, b int64, c float64, d bool) {\n        fmt.Println(args, a, b, c, d)\n    })\n}),\n```\n\n### example of execution results\n\n**go run main.go --help**\n\n```text\nNAME:\n        tool - help tool\nSYNOPSIS:\n        tool   [arg]\nCOMMANDS:\n        one   first level\n\n```\n\n**go run main.go simple --help**\n\n```text\nNAME\n        tool - help tool\nSYNOPSIS\n        tool simple [arg]\nDESCRIPTION\n        first-level command\nARGUMENTS\n        -a       this is a string argument (default: demo)\n        -b       this is a int64 argument (default: 1)\n        --cc     this is a float64 argument (default: 1e-05)\n        -e       this is a bool argument (default: false)\n\n```\n\n## Creating multi-level command tree\n\nTo create a multi-level command tree,\nyou need to add the child command to the parent via the `AddCommand` method.\n\nAt the same time, in the parent command, it is enough to\nspecify only the name and description via the `Setup` method.\n\n```go\nroot := console.New(\"tool\", \"help tool\")\n\nsimpleCmd := console.NewCommand(func(setter console.CommandSetter) {\n    setter.Setup(\"simple\", \"third level\")\n    ....\n})\n\ntwoCmd := console.NewCommand(func(setter console.CommandSetter) {\n    setter.Setup(\"two\", \"second level\")\n    setter.AddCommand(simpleCmd)\n})\n\noneCmd := console.NewCommand(func(setter console.CommandSetter) {\n    setter.Setup(\"one\", \"first level\")\n    setter.AddCommand(twoCmd)\n})\n\nroot.AddCommand(oneCmd)\nroot.Exec()\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosspkg%2Fgo-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosspkg%2Fgo-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosspkg%2Fgo-console/lists"}