{"id":24196862,"url":"https://github.com/sebastianwebber/cmdr","last_synced_at":"2025-10-29T22:36:32.271Z","repository":{"id":57518855,"uuid":"117450624","full_name":"sebastianwebber/cmdr","owner":"sebastianwebber","description":"golang helpers to call OS commands","archived":false,"fork":false,"pushed_at":"2020-07-21T14:00:00.000Z","size":24,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-19T04:08:27.079Z","etag":null,"topics":["bash","cmd","command-line","command-line-tool","exec","golang","helper"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastianwebber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-14T17:20:01.000Z","updated_at":"2023-12-16T13:18:02.000Z","dependencies_parsed_at":"2022-09-26T18:00:43.500Z","dependency_job_id":null,"html_url":"https://github.com/sebastianwebber/cmdr","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianwebber%2Fcmdr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianwebber%2Fcmdr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianwebber%2Fcmdr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastianwebber%2Fcmdr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastianwebber","download_url":"https://codeload.github.com/sebastianwebber/cmdr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233799535,"owners_count":18732178,"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":["bash","cmd","command-line","command-line-tool","exec","golang","helper"],"created_at":"2025-01-13T19:38:30.745Z","updated_at":"2025-09-21T21:31:59.685Z","avatar_url":"https://github.com/sebastianwebber.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cmdr\n[![Build Status](https://travis-ci.org/sebastianwebber/cmdr.svg?branch=master)](https://travis-ci.org/sebastianwebber/cmdr) [![Go Report Card](https://goreportcard.com/badge/github.com/sebastianwebber/cmdr)](https://goreportcard.com/report/github.com/sebastianwebber/cmdr) [![codecov](https://codecov.io/gh/sebastianwebber/cmdr/branch/master/graph/badge.svg)](https://codecov.io/gh/sebastianwebber/cmdr)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsebastianwebber%2Fcmdr.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsebastianwebber%2Fcmdr?ref=badge_shield)\n\n\n`cmdr` (pronounced  _\"commander\"_) is a go package to abstract and simplify execution of commands on the operation system.\n\n## how to use it\n\nFirst things first:\n```\ngo get -u -v go get github.com/sebastianwebber/cmdr\n```\n\n\nBasically create a `Command` and call the `Run` function. Take a look:\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sebastianwebber/cmdr\"\n)\n\nfunc main() {\n    // *** short version ***********\n\tout, err := cmdr.New(true, \"ls\", \"-lh\", \"~/tmp2/*\").Run()\n\tfmt.Println(\"Output:\", string(out))\n\tif err != nil {\n\t\tfmt.Println(\"OOPS:\", err.Error())\n    }\n\n    // *** verbose version ***********\n\t// New is a helper to create a Command\n\t// You can call it by a shell like bash if you want (useful to process expressions like *)\n\tcmd := cmdr.New(true, \"ls\", \"-lh\", \"~/tmp/*\")\n\n\t// You can declare the variable as well:\n\t// cmd := cmdr.Command{  }\n\n\t// You can also parse a command into a Command:\n\t// cmd := cmdr.Parse(`psql -At -c 'select now();'`)\n\n\t// Enable timeout if you want (5s by example)\n\tcmd.Options.Timeout = 5\n\n\t// To check if the inputed command is valid, use the IsValid function.\n\t// It checks if the command exists in PATH\n\tif cmd.IsValid() {\n\n\t\t// To execute the command, just call the Run function\n\t\tout, err := cmd.Run()\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\n\t\t// here comes the output\n\t\tfmt.Println(string(out))\n\t}\n}\n```\n\n## Grouping commands\n\nIts possible to group a list of commands:\n\n```golang\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/sebastianwebber/cmdr\"\n)\n\nfunc main() {\n    // Group options (experimental)\n    total, err := cmdr.Group(\n        cmdr.AbortOnError,\n        cmdr.New(false, \"ls\", \"-lh\"),\n        cmdr.New(false, \"pwd 123q6236\"),\n        cmdr.New(false, \"cat\", \"/etc/hosts\"),\n    )\n    fmt.Printf(\"%d commands executed without error. \\n\", total)\n\n    if err != nil {\n        fmt.Printf(\"Houston, we have a problem! %v\\n\", err)\n    }\n}\n```\n\u003e **This is a work in progress.**\n\n\n## TODO List\n\n- [x] Add option to timeout\n- [x] Enable way to group commands\n- [ ] Print output of each command in the group (perhaps adding a `name` option?)\n- [ ] Pipe support\n- [ ] add support por multiple commands\n\n\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsebastianwebber%2Fcmdr.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsebastianwebber%2Fcmdr?ref=badge_large)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastianwebber%2Fcmdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastianwebber%2Fcmdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastianwebber%2Fcmdr/lists"}