{"id":13840801,"url":"https://github.com/google/subcommands","last_synced_at":"2025-07-11T09:33:21.894Z","repository":{"id":37286325,"uuid":"52376121","full_name":"google/subcommands","owner":"google","description":"Go subcommand library.","archived":false,"fork":false,"pushed_at":"2022-11-17T00:00:06.000Z","size":20,"stargazers_count":756,"open_issues_count":12,"forks_count":49,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-17T12:45:54.535Z","etag":null,"topics":[],"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/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-23T17:02:31.000Z","updated_at":"2024-11-13T07:50:34.000Z","dependencies_parsed_at":"2023-01-20T20:02:24.819Z","dependency_job_id":null,"html_url":"https://github.com/google/subcommands","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fsubcommands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fsubcommands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fsubcommands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fsubcommands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/subcommands/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225712721,"owners_count":17512466,"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":[],"created_at":"2024-08-04T17:00:55.961Z","updated_at":"2024-11-21T10:30:46.928Z","avatar_url":"https://github.com/google.png","language":"Go","readme":"# subcommands #\n\n[![GoDoc](https://godoc.org/github.com/google/subcommands?status.svg)](https://godoc.org/github.com/google/subcommands)  \nSubcommands is a Go package that implements a simple way for a single command to\nhave many subcommands, each of which takes arguments and so forth.\n\nThis is not an official Google product.\n\n## Usage ##\n\nSet up a 'print' subcommand:\n\n```go\nimport (\n  \"context\"\n  \"flag\"\n  \"fmt\"\n  \"os\"\n  \"strings\"\n\n  \"github.com/google/subcommands\"\n)\n\ntype printCmd struct {\n  capitalize bool\n}\n\nfunc (*printCmd) Name() string     { return \"print\" }\nfunc (*printCmd) Synopsis() string { return \"Print args to stdout.\" }\nfunc (*printCmd) Usage() string {\n  return `print [-capitalize] \u003csome text\u003e:\n  Print args to stdout.\n`\n}\n\nfunc (p *printCmd) SetFlags(f *flag.FlagSet) {\n  f.BoolVar(\u0026p.capitalize, \"capitalize\", false, \"capitalize output\")\n}\n\nfunc (p *printCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {\n  for _, arg := range f.Args() {\n    if p.capitalize {\n      arg = strings.ToUpper(arg)\n    }\n    fmt.Printf(\"%s \", arg)\n  }\n  fmt.Println()\n  return subcommands.ExitSuccess\n}\n```\n\nRegister using the default Commander, also use some built in subcommands,\nfinally run Execute using ExitStatus as the exit code:\n\n```go\nfunc main() {\n  subcommands.Register(subcommands.HelpCommand(), \"\")\n  subcommands.Register(subcommands.FlagsCommand(), \"\")\n  subcommands.Register(subcommands.CommandsCommand(), \"\")\n  subcommands.Register(\u0026printCmd{}, \"\")\n\n  flag.Parse()\n  ctx := context.Background()\n  os.Exit(int(subcommands.Execute(ctx)))\n}\n```\n\n","funding_links":[],"categories":["Go","Go (531)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fsubcommands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fsubcommands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fsubcommands/lists"}