{"id":25770395,"url":"https://github.com/broothie/cob","last_synced_at":"2026-05-15T00:07:30.771Z","repository":{"id":279025793,"uuid":"937514368","full_name":"broothie/cob","owner":"broothie","description":"A Go package for building shell commands","archived":false,"fork":false,"pushed_at":"2025-02-23T08:44:21.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T09:27:19.491Z","etag":null,"topics":["go","shell"],"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/broothie.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":"2025-02-23T08:40:16.000Z","updated_at":"2025-02-23T08:44:25.000Z","dependencies_parsed_at":"2025-02-23T09:27:27.926Z","dependency_job_id":"08747632-f775-44b6-a560-617438e85f7e","html_url":"https://github.com/broothie/cob","commit_stats":null,"previous_names":["broothie/cob"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broothie%2Fcob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broothie%2Fcob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broothie%2Fcob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broothie%2Fcob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/broothie","download_url":"https://codeload.github.com/broothie/cob/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240966118,"owners_count":19886022,"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":["go","shell"],"created_at":"2025-02-27T02:29:16.722Z","updated_at":"2026-05-15T00:07:30.424Z","avatar_url":"https://github.com/broothie.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cob` 🌽 COmmand Builder\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/broothie/cob.svg)](https://pkg.go.dev/github.com/broothie/cob)\n[![codecov](https://codecov.io/gh/broothie/cob/graph/badge.svg?token=FgyhQS4tMX)](https://codecov.io/gh/broothie/cob)\n[![gosec](https://github.com/broothie/cob/actions/workflows/gosec.yml/badge.svg)](https://github.com/broothie/cob/actions/workflows/gosec.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/broothie/cob)](https://goreportcard.com/report/github.com/broothie/cob)\n\n`cob` is a Go package for building and running `*exec.Cmd` objects.\n\n## Installation\n\n```shell\ngo get github.com/broothie/cob@latest\n```\n\n## Documentation\n\nDetailed documentation can be found at [pkg.go.dev](https://pkg.go.dev/github.com/broothie/cob).\n\n## Usage\n\n```go\n// Easily build `*exec.Cmd` objects:\ncmd, err := cob.New(ctx, \"echo\",\n\tcob.AddArgs(\"Hello\", \"World\"),\n\tcob.AddEnv(\"SHELL\", \"bash\"),\n\tcob.SetStdout(os.Stdout),\n)\n\n// Or, run them and easily get `stdout` and `stderr`:\nstdout, stderr, cmd, err := cob.Output(ctx, \"echo\", cob.AddArgs(\"Hello\", \"World\"))\n```\n\nHere is a list of all available options:\n\n```go\ncmd, err := cob.New(ctx, \"echo\",\n\tcob.SetArgs(\"Hello\", \"World\"),         // Set args directly\n\tcob.AddArgs(\"more\", \"args\"),           // Add to existing args\n\tcob.SetEnv(\"SHELL=bash\"),              // Set env directly\n\tcob.AddEnv(\"SHELL\", \"bash\"),           // Add to existing env\n\tcob.SetStdin(os.Stdin),                // Set stdin directly\n\tcob.AddStdins(someReader),             // Add to existing stdin\n\tcob.SetStdout(os.Stdout),              // Set stdout directly\n\tcob.AddStdouts(someWriter),            // Add to existing stdout\n\tcob.SetStderr(os.Stderr),              // Set stderr directly\n\tcob.AddStderrs(errorWriter),           // Add to existing stderr\n\tcob.SetDir(\"/tmp\"),                    // Set working directory\n\tcob.SetExtraFiles(os.Stdin),           // Set extra files directly\n\tcob.AddExtraFiles(someFile),           // Add to existing extra files\n\tcob.SetSysProcAttr(\u0026syscall.SysProcAttr{}),  // Set process attributes\n\tcob.SetWaitDelay(time.Second),         // Set timeout for Wait()\n)\n```\n\n## Why?\n\nThe `*exec.Cmd` API isn't terrible by any means,\nI just find building the actual `*exec.Cmd` objects to be somewhat cumbersome.\n\nWith this library we go from this:\n\n```go\nstdout := new(bytes.Buffer)\nstderr := new(bytes.Buffer)\n\ncmd := exec.CommandContext(ctx, \"command\", \"arg1\", \"arg2\")\ncmd.Stdin = os.Stdin\ncmd.Stdout = io.MultiWriter(stdout, os.Stdout)\ncmd.Stderr = stderr\ncmd.Env = append(cmd.Env, fmt.Sprintf(\"%s=%s\", key, value))\n\nif err := cmd.Run(); err != nil {\n\treturn err\n}\n```\n\nto this:\n\n```go\nstdout, stderr, cmd, err := cmd.Output(ctx, \"command\",\n\tcob.AddArgs(\"arg1\", \"arg2\"),\n\tcob.SetStdin(os.Stdin),\n\tcob.AddStdouts(os.Stdout),\n\tcob.AddEnv(key, value),\n)\nif err != nil {\n\treturn err\n}\n```\n\nwhich I personally find clearer and more concise.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroothie%2Fcob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbroothie%2Fcob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroothie%2Fcob/lists"}