{"id":19965925,"url":"https://github.com/stephen-fox/userutil","last_synced_at":"2025-09-19T17:31:17.976Z","repository":{"id":96737698,"uuid":"145265732","full_name":"stephen-fox/userutil","owner":"stephen-fox","description":"A Go library for working with users on the command line.","archived":false,"fork":false,"pushed_at":"2018-12-20T14:57:33.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T23:17:42.228Z","etag":null,"topics":["command-line","userinput"],"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/stephen-fox.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-08-19T02:00:20.000Z","updated_at":"2018-12-20T14:57:04.000Z","dependencies_parsed_at":"2023-08-17T23:05:12.044Z","dependency_job_id":null,"html_url":"https://github.com/stephen-fox/userutil","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephen-fox%2Fuserutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephen-fox%2Fuserutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephen-fox%2Fuserutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephen-fox%2Fuserutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephen-fox","download_url":"https://codeload.github.com/stephen-fox/userutil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233581573,"owners_count":18697669,"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":["command-line","userinput"],"created_at":"2024-11-13T02:32:19.236Z","updated_at":"2025-09-19T17:31:12.691Z","avatar_url":"https://github.com/stephen-fox.png","language":"Go","readme":"# userutil\n\n## What is it?\nA Go library for working with users on the command line.\n\n## API\n\n#### User input\nThe library's API offers several helpful functions for working with user input.\nPrompting for user input can be configured using a `PromptOptions` struct.\nPassing an empty `PromptOptions` will use the default options.\n\nFor example, you can prompt a user to answer a question:\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/stephen-fox/userutil\"\n)\n\nfunc main() {\n\tresult, err := userutil.GetUserInput(\"How is your day going?\", userutil.PromptOptions{})\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tlog.Println(\"You said: '\" + result + \"'\")\n}\n```\n\nIf you wanted to hide user input, you can specify so using the `PromptOptions`:\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/stephen-fox/userutil\"\n)\n\nfunc main() {\n\toptions := userutil.PromptOptions{\n\t\tShouldHideInput: true,\n\t}\n\tresult, err := userutil.GetUserInput(\"Say something nice\", options)\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tlog.Println(\"You said: '\" + result + \"'\")\n}\n```\n\nYou can also prompt for a \"yes or no\" answer:\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/stephen-fox/userutil\"\n)\n\nfunc main() {\n\tansweredYes, err := userutil.GetYesOrNoUserInput(\"Is today a nice day?\", userutil.PromptOptions{})\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tif answeredYes {\n\t\tlog.Println(\"You said yes\")\n\t} else {\n\t\tlog.Println(\"You said no\")\n\t}\n}\n```\n\n#### Admin permissions\nYou can also check if the current user is `root` (or an `Administrator`):\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/stephen-fox/userutil\"\n)\n\nfunc main() {\n\terr := userutil.IsRoot()\n\tif err != nil {\n\t\tlog.Fatal(err.Error())\n\t}\n\n\tlog.Println(\"You are root\")\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephen-fox%2Fuserutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephen-fox%2Fuserutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephen-fox%2Fuserutil/lists"}