{"id":16517645,"url":"https://github.com/rfyiamcool/go-shell","last_synced_at":"2025-08-10T08:12:47.748Z","repository":{"id":57537339,"uuid":"275773645","full_name":"rfyiamcool/go-shell","owner":"rfyiamcool","description":"golang easy shell \u0026\u0026 command lib","archived":false,"fork":false,"pushed_at":"2021-08-18T01:55:28.000Z","size":82,"stargazers_count":84,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-06T12:53:46.562Z","etag":null,"topics":["command","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rfyiamcool.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":"2020-06-29T08:24:34.000Z","updated_at":"2025-06-19T07:59:08.000Z","dependencies_parsed_at":"2022-09-04T13:50:49.536Z","dependency_job_id":null,"html_url":"https://github.com/rfyiamcool/go-shell","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rfyiamcool/go-shell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfyiamcool%2Fgo-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfyiamcool%2Fgo-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfyiamcool%2Fgo-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfyiamcool%2Fgo-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rfyiamcool","download_url":"https://codeload.github.com/rfyiamcool/go-shell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfyiamcool%2Fgo-shell/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269693593,"owners_count":24460248,"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-08-10T02:00:08.965Z","response_time":71,"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":["command","go","shell"],"created_at":"2024-10-11T16:33:06.709Z","updated_at":"2025-08-10T08:12:47.720Z","avatar_url":"https://github.com/rfyiamcool.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo.png](logo.png)\n\n# go-shell\n\neasy execute shell, better `os/exec`\n\n## Feature\n\n* simple api\n* add timeout\n* add stop()\n* add yum api\n* use channel to send stdout and stderr\n* merge stdout and stderr to new output\n* use sync.pool to reduce alloc buffer\n\n## Usage\n\n😁 **Look at the code for yourself**\n\n```golang\nfunc TestCheckOutput(t *testing.T) {\n\tcmd := NewCommand(\"echo -n 123123\")\n\tcmd.Run() // start and wait\n\tstatus := cmd.Status\n\n\tassert.Equal(t, status.Output, \"123123\")\n\tassert.Equal(t, status.Stdout, \"123123\")\n\tassert.Equal(t, status.Stderr, \"\")\n}\n\nfunc TestCheckStderr(t *testing.T) {\n\tcmd := NewCommand(\"echo -n \\\"123123\\\" \u003e\u00262\")\n\tcmd.Run() // start and wait\n\tstatus := cmd.Status\n\n\tassert.Equal(t, status.Stdout, \"\")\n\tassert.Equal(t, status.Output, \"123123\")\n\tassert.Equal(t, status.Stderr, \"123123\")\n}\n\nfunc TestDelayStop(t *testing.T) {\n\tstart := time.Now()\n\tcmd := NewCommand(\"sleep 5;echo 123;sleep 123\")\n\tcmd.Start() // async start\n\n\tgo func() {\n\t\ttime.Sleep(1 * time.Second)\n\t\tcmd.Stop()\n\t}()\n\n\tcmd.Wait() // wait\n\tend := time.Since(start)\n\tassert.Less(t, end.Seconds(), float64(2))\n}\n\nfunc TestRunTimeout(t *testing.T) {\n\tcmd := NewCommand(\"echo 123; sleep 5\", WithTimeout(2))\n\tcmd.Start()\n\tcmd.Wait()\n\tstatus := cmd.Status\n\n\tassert.Equal(t, status.Error, ErrProcessTimeout)\n\tassert.Greater(t, status.CostTime.Seconds(), float64(2))\n\tassert.Less(t, status.CostTime.Seconds(), float64(3))\n}\n\nfunc TestCheckStderr(t *testing.T) {\n\tcmd := NewCommand(\"echo -n \\\"123123\\\" \u003e\u00262\") // echo stderr\n\tcmd.Run() // start and wait\n\tstatus := cmd.Status\n\n\tassert.Equal(t, status.Stdout, \"\")\n\tassert.Equal(t, status.Output, \"123123\")\n\tassert.Equal(t, status.Stderr, \"123123\")\n}\n\nfunc TestCheckStream(t *testing.T) {\n\tstdoutChan := make(chan string, 100)\n\tincr := 0\n\tgo func() {\n\t\tfor line := range stdoutChan {\n\t\t\tincr++\n\t\t\tfmt.Println(incr, line)\n\t\t}\n\t}()\n\n\tcmd := exec.Command(\"bash\", \"-c\", \"echo 123;sleep 1;echo 456; echo 789\")\n\tstdout := NewOutputStream(stdoutChan)\n\tcmd.Stdout = stdout\n\tcmd.Run()\n\n\tassert.Equal(t, incr, 3)\n}\n\nfunc TestCheckBuffer(t *testing.T) {\n\tcmd := exec.Command(\"bash\", \"-c\", \"echo 123\")\n\tstdout := NewOutputBuffer()\n\tcmd.Stdout = stdout\n\tcmd.Run()\n\n\tassert.Equal(t, stdout.buf.String(), \"123\\n\")\n\tassert.Equal(t, stdout.Lines()[0], \"123\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfyiamcool%2Fgo-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frfyiamcool%2Fgo-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfyiamcool%2Fgo-shell/lists"}