{"id":13644916,"url":"https://github.com/Netflix/go-expect","last_synced_at":"2025-04-21T10:34:54.498Z","repository":{"id":33508872,"uuid":"133400872","full_name":"Netflix/go-expect","owner":"Netflix","description":"an expect-like golang library to automate control of terminal or console based programs.","archived":false,"fork":false,"pushed_at":"2024-06-15T04:55:13.000Z","size":80,"stargazers_count":440,"open_issues_count":9,"forks_count":66,"subscribers_count":313,"default_branch":"master","last_synced_at":"2024-11-17T12:33:25.349Z","etag":null,"topics":["automation","cli","expect"],"latest_commit_sha":null,"homepage":null,"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/Netflix.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":"2018-05-14T17:53:19.000Z","updated_at":"2024-11-12T02:23:51.000Z","dependencies_parsed_at":"2024-01-14T09:25:50.721Z","dependency_job_id":"0a4d76c3-c935-4531-a8ec-654eefbcb7a6","html_url":"https://github.com/Netflix/go-expect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fgo-expect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fgo-expect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fgo-expect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fgo-expect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Netflix","download_url":"https://codeload.github.com/Netflix/go-expect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250040999,"owners_count":21365195,"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":["automation","cli","expect"],"created_at":"2024-08-02T01:02:19.266Z","updated_at":"2025-04-21T10:34:49.486Z","avatar_url":"https://github.com/Netflix.png","language":"Go","readme":"# go-expect\n\n![Go](https://github.com/Netflix/go-expect/workflows/Go/badge.svg)\n[![Build Status](https://travis-ci.com/Netflix/go-expect.svg?branch=master)](https://travis-ci.com/Netflix/go-expect)\n[![GoDoc](https://godoc.org/github.com/Netflix/go-expect?status.svg)](https://godoc.org/github.com/Netflix/go-expect)\n[![NetflixOSS Lifecycle](https://img.shields.io/osslifecycle/Netflix/go-expect.svg)]()\n\nPackage expect provides an expect-like interface to automate control of applications. It is unlike expect in that it does not spawn or manage process lifecycle. This package only focuses on expecting output and sending input through it's pseudoterminal.\n\n## Usage\n\n### `os.Exec` example\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\t\"os/exec\"\n\t\"time\"\n\n\texpect \"github.com/Netflix/go-expect\"\n)\n\nfunc main() {\n\tc, err := expect.NewConsole(expect.WithStdout(os.Stdout))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer c.Close()\n\n\tcmd := exec.Command(\"vi\")\n\tcmd.Stdin = c.Tty()\n\tcmd.Stdout = c.Tty()\n\tcmd.Stderr = c.Tty()\n\n\tgo func() {\n\t\tc.ExpectEOF()\n\t}()\n\n\terr = cmd.Start()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\ttime.Sleep(time.Second)\n\tc.Send(\"iHello world\\x1b\")\n\ttime.Sleep(time.Second)\n\tc.Send(\"dd\")\n\ttime.Sleep(time.Second)\n\tc.SendLine(\":q!\")\n\n\terr = cmd.Wait()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n### `golang.org/x/crypto/ssh/terminal` example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"golang.org/x/crypto/ssh/terminal\"\n\n\texpect \"github.com/Netflix/go-expect\"\n)\n\nfunc getPassword(fd int) string {\n\tbytePassword, _ := terminal.ReadPassword(fd)\n\n\treturn string(bytePassword)\n}\n\nfunc main() {\n\tc, _ := expect.NewConsole()\n\n\tdefer c.Close()\n\n\tdonec := make(chan struct{})\n\tgo func() {\n\t\tdefer close(donec)\n\t\tc.SendLine(\"hunter2\")\n\t}()\n\n\techoText := getPassword(int(c.Tty().Fd()))\n\n\t\u003c-donec\n\n\tfmt.Printf(\"\\nPassword from stdin: %s\", echoText)\n}\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetflix%2Fgo-expect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNetflix%2Fgo-expect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetflix%2Fgo-expect/lists"}