{"action":"created","issue":{"url":"https://api.github.com/repos/TylorS/reginn/issues/5","repository_url":"https://api.github.com/repos/TylorS/reginn","labels_url":"https://api.github.com/repos/TylorS/reginn/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/TylorS/reginn/issues/5/comments","events_url":"https://api.github.com/repos/TylorS/reginn/issues/5/events","html_url":"https://github.com/TylorS/reginn/issues/5","id":183413068,"number":5,"title":"Prompts","user":{"login":"ivan-kleshnin","id":2128182,"avatar_url":"https://avatars.githubusercontent.com/u/2128182?v=3","gravatar_id":"","url":"https://api.github.com/users/ivan-kleshnin","html_url":"https://github.com/ivan-kleshnin","followers_url":"https://api.github.com/users/ivan-kleshnin/followers","following_url":"https://api.github.com/users/ivan-kleshnin/following{/other_user}","gists_url":"https://api.github.com/users/ivan-kleshnin/gists{/gist_id}","starred_url":"https://api.github.com/users/ivan-kleshnin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivan-kleshnin/subscriptions","organizations_url":"https://api.github.com/users/ivan-kleshnin/orgs","repos_url":"https://api.github.com/users/ivan-kleshnin/repos","events_url":"https://api.github.com/users/ivan-kleshnin/events{/privacy}","received_events_url":"https://api.github.com/users/ivan-kleshnin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/TylorS/reginn/labels/Type:%20Discussion","name":"Type: Discussion","color":"ffff00"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-17T13:16:02Z","updated_at":"2016-10-18T01:21:09Z","closed_at":"2016-10-18T01:21:09Z","body":"Hi, Tylor. Great API, I've really enjoyed reading through the docs! \r\n\r\nDo you plan to add prompts?\r\n\r\n### Motivation\r\nSome CLI operations are destructive and need to be additionally confirmed by user.\r\nEven better when such confirmations provide additional information. \r\n\r\nI imagine something like:\r\n\r\n```\r\n$ node ./cli.js rm */*.txt\r\n```\r\n\r\n```\r\n- folder1/foo.txt\r\n- folder2/bar.txt\r\n- bazz.txt\r\nare going to be removed\r\nConfirm (y/n): _ \r\n```"},"comment":{"url":"https://api.github.com/repos/TylorS/reginn/issues/comments/254380611","html_url":"https://github.com/TylorS/reginn/issues/5#issuecomment-254380611","issue_url":"https://api.github.com/repos/TylorS/reginn/issues/5","id":254380611,"user":{"login":"TylorS","id":6282473,"avatar_url":"https://avatars.githubusercontent.com/u/6282473?v=3","gravatar_id":"","url":"https://api.github.com/users/TylorS","html_url":"https://github.com/TylorS","followers_url":"https://api.github.com/users/TylorS/followers","following_url":"https://api.github.com/users/TylorS/following{/other_user}","gists_url":"https://api.github.com/users/TylorS/gists{/gist_id}","starred_url":"https://api.github.com/users/TylorS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylorS/subscriptions","organizations_url":"https://api.github.com/users/TylorS/orgs","repos_url":"https://api.github.com/users/TylorS/repos","events_url":"https://api.github.com/users/TylorS/events{/privacy}","received_events_url":"https://api.github.com/users/TylorS/received_events","type":"User","site_admin":false},"created_at":"2016-10-18T01:21:09Z","updated_at":"2016-10-18T01:21:09Z","body":"Hey @ivan-kleshnin thanks for the kind words, I hope that this proves useful to you in some way.\r\n\r\nI've not really thought about adding prompts. I was really trying to keep things minimal. By documenting the types the library works, I figured that would make it easier to extend the library. For example you could create a custom `run()` and `commandWithPrompts()` maybe, but that's probably more work than it's worth in many cases. \r\n\r\nI'd probably suggest using something like [`inquirer`](https://github.com/SBoudrias/Inquirer.js/)\r\nYour proposed command might look something like\r\n\r\n```js\r\nimport { command, alias, run, asPromise } from 'reginn'\r\nimport { prompt } from 'inquirer'\r\nimport rimraf from 'rimraf'\r\n\r\nconst remove = command(alias('rm'))\r\n\r\nasPromise(remove)\r\n  .then(({ args }) => {\r\n\r\n    const areYouSure = {\r\n      type: 'confirm',\r\n      name: 'confirm',\r\n      message: `\\n - ${args.join('\\n - ')}\\n are going to be removed\\n Confirm (y/n):`  \r\n    }\r\n\r\n    prompt([ areYouSure ]).then(answers => {\r\n      if (answer.confirm) {\r\n        args.forEach(file => rimraf(file, (err) => {\r\n          if (err) throw err\r\n        }))\r\n      }\r\n    })\r\n  })\r\n\r\nrun(remove) \r\n```\r\n\r\nI don't have any idea if this example will actually run, but I hope it demonstrates how it could be possible to include prompts inside of your handler functions.\r\n\r\nI'm going to close this as a discussion for now, please reopen if you think this is an invalid answer, and feel free to continue the discussion. "}}
{"actor":{"display_login":"TylorS"}}