{"action":"created","comment":{"url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/comments/231326958","pull_request_review_id":172275599,"id":231326958,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTMyNjk1OA==","diff_hunk":"@@ -143,6 +141,29 @@ export class BeautifyCommand extends BaseCommand {\n       });\n     });\n   }\n+\n+  private validateLanguage(\n+    language: string | undefined,\n+    unibeautify: Unibeautify\n+  ) {\n+    if (!language) {\n+      const error = new Error(\"A language is required.\");\n+      return this.handleError(error, 1);\n+    }\n+    const langs = unibeautify.findLanguages({ name: language });\n+    if (langs.length === 0) {\n+      const bestMatchLanguage = getAllLanguages().find(lang => {\n+        return lang.toLowerCase() === language.toLowerCase();","path":"src/commands/BeautifyCommand.ts","position":80,"original_position":80,"commit_id":"c6766f8924a7b3b712cb0d7ca76292b52b10452f","original_commit_id":"c6766f8924a7b3b712cb0d7ca76292b52b10452f","user":{"login":"Glavin001","id":1885333,"node_id":"MDQ6VXNlcjE4ODUzMzM=","avatar_url":"https://avatars0.githubusercontent.com/u/1885333?v=4","gravatar_id":"","url":"https://api.github.com/users/Glavin001","html_url":"https://github.com/Glavin001","followers_url":"https://api.github.com/users/Glavin001/followers","following_url":"https://api.github.com/users/Glavin001/following{/other_user}","gists_url":"https://api.github.com/users/Glavin001/gists{/gist_id}","starred_url":"https://api.github.com/users/Glavin001/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Glavin001/subscriptions","organizations_url":"https://api.github.com/users/Glavin001/orgs","repos_url":"https://api.github.com/users/Glavin001/repos","events_url":"https://api.github.com/users/Glavin001/events{/privacy}","received_events_url":"https://api.github.com/users/Glavin001/received_events","type":"User","site_admin":false},"body":"I would be OK if you also wanted to add https://www.npmjs.com/package/fast-levenshtein\r\n\r\ncc @lassik @muuvmuuv\r\n\r\nSomething like:\r\n\r\n```typescript\r\nconst languages = getAllLanguages();\r\n\r\nconst distances: number[] = languages.map(lang =>\r\n  levenshtein.get(lang.toLowerCase(), language.toLowerCase())\r\n);\r\nconst bestDistance: number = Math.min(...distances);\r\n\r\nconst bestMatchLanguages = getAllLanguages().filter((lang, index) =>\r\n  distances[index] === bestDistance\r\n);\r\n\r\n// ...\r\n\r\nconst error = new Error(\r\n  `Language '${language}' was not found. Did you mean '${bestMatchLanguages.join(\" or \")}'?`\r\n);\r\n```\r\n\r\nThe above only gets the best. It could also be modified to support an arbitrary threshold:\r\n\r\n```diff\r\n- distances[index] === bestDistance\r\n+ const distanceThreshold = 2;\r\n+ distances[index] <= (bestDistance + distanceThreshold)\r\n```\r\n\r\nSo `C` would also show `C++` and visa versa 😉 .\r\n","created_at":"2018-11-06T23:02:59Z","updated_at":"2018-11-06T23:03:03Z","html_url":"https://github.com/Unibeautify/unibeautify-cli/pull/116#discussion_r231326958","pull_request_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/comments/231326958"},"html":{"href":"https://github.com/Unibeautify/unibeautify-cli/pull/116#discussion_r231326958"},"pull_request":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116","id":228768793,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI4NzY4Nzkz","html_url":"https://github.com/Unibeautify/unibeautify-cli/pull/116","diff_url":"https://github.com/Unibeautify/unibeautify-cli/pull/116.diff","patch_url":"https://github.com/Unibeautify/unibeautify-cli/pull/116.patch","issue_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/116","number":116,"state":"open","locked":false,"title":"Suggest language when one isn't found","user":{"login":"stevenzeck","id":8315038,"node_id":"MDQ6VXNlcjgzMTUwMzg=","avatar_url":"https://avatars1.githubusercontent.com/u/8315038?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenzeck","html_url":"https://github.com/stevenzeck","followers_url":"https://api.github.com/users/stevenzeck/followers","following_url":"https://api.github.com/users/stevenzeck/following{/other_user}","gists_url":"https://api.github.com/users/stevenzeck/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenzeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenzeck/subscriptions","organizations_url":"https://api.github.com/users/stevenzeck/orgs","repos_url":"https://api.github.com/users/stevenzeck/repos","events_url":"https://api.github.com/users/stevenzeck/events{/privacy}","received_events_url":"https://api.github.com/users/stevenzeck/received_events","type":"User","site_admin":false},"body":"Closes #115  \r\n\r\n* Suggests a language if the provided language `-l` is not found","created_at":"2018-11-06T17:12:23Z","updated_at":"2018-11-06T23:03:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c35f9850f96872f5f2ef885d34861916b0dcb2fc","assignee":{"login":"stevenzeck","id":8315038,"node_id":"MDQ6VXNlcjgzMTUwMzg=","avatar_url":"https://avatars1.githubusercontent.com/u/8315038?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenzeck","html_url":"https://github.com/stevenzeck","followers_url":"https://api.github.com/users/stevenzeck/followers","following_url":"https://api.github.com/users/stevenzeck/following{/other_user}","gists_url":"https://api.github.com/users/stevenzeck/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenzeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenzeck/subscriptions","organizations_url":"https://api.github.com/users/stevenzeck/orgs","repos_url":"https://api.github.com/users/stevenzeck/repos","events_url":"https://api.github.com/users/stevenzeck/events{/privacy}","received_events_url":"https://api.github.com/users/stevenzeck/received_events","type":"User","site_admin":false},"assignees":[{"login":"stevenzeck","id":8315038,"node_id":"MDQ6VXNlcjgzMTUwMzg=","avatar_url":"https://avatars1.githubusercontent.com/u/8315038?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenzeck","html_url":"https://github.com/stevenzeck","followers_url":"https://api.github.com/users/stevenzeck/followers","following_url":"https://api.github.com/users/stevenzeck/following{/other_user}","gists_url":"https://api.github.com/users/stevenzeck/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenzeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenzeck/subscriptions","organizations_url":"https://api.github.com/users/stevenzeck/orgs","repos_url":"https://api.github.com/users/stevenzeck/repos","events_url":"https://api.github.com/users/stevenzeck/events{/privacy}","received_events_url":"https://api.github.com/users/stevenzeck/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":420333368,"node_id":"MDU6TGFiZWw0MjAzMzMzNjg=","url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116/commits","review_comments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116/comments","review_comment_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/116/comments","statuses_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/statuses/c6766f8924a7b3b712cb0d7ca76292b52b10452f","head":{"label":"Unibeautify:suggest-language","ref":"suggest-language","sha":"c6766f8924a7b3b712cb0d7ca76292b52b10452f","user":{"login":"Unibeautify","id":21251312,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjUxMzEy","avatar_url":"https://avatars3.githubusercontent.com/u/21251312?v=4","gravatar_id":"","url":"https://api.github.com/users/Unibeautify","html_url":"https://github.com/Unibeautify","followers_url":"https://api.github.com/users/Unibeautify/followers","following_url":"https://api.github.com/users/Unibeautify/following{/other_user}","gists_url":"https://api.github.com/users/Unibeautify/gists{/gist_id}","starred_url":"https://api.github.com/users/Unibeautify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unibeautify/subscriptions","organizations_url":"https://api.github.com/users/Unibeautify/orgs","repos_url":"https://api.github.com/users/Unibeautify/repos","events_url":"https://api.github.com/users/Unibeautify/events{/privacy}","received_events_url":"https://api.github.com/users/Unibeautify/received_events","type":"Organization","site_admin":false},"repo":{"id":65061973,"node_id":"MDEwOlJlcG9zaXRvcnk2NTA2MTk3Mw==","name":"unibeautify-cli","full_name":"Unibeautify/unibeautify-cli","private":false,"owner":{"login":"Unibeautify","id":21251312,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjUxMzEy","avatar_url":"https://avatars3.githubusercontent.com/u/21251312?v=4","gravatar_id":"","url":"https://api.github.com/users/Unibeautify","html_url":"https://github.com/Unibeautify","followers_url":"https://api.github.com/users/Unibeautify/followers","following_url":"https://api.github.com/users/Unibeautify/following{/other_user}","gists_url":"https://api.github.com/users/Unibeautify/gists{/gist_id}","starred_url":"https://api.github.com/users/Unibeautify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unibeautify/subscriptions","organizations_url":"https://api.github.com/users/Unibeautify/orgs","repos_url":"https://api.github.com/users/Unibeautify/repos","events_url":"https://api.github.com/users/Unibeautify/events{/privacy}","received_events_url":"https://api.github.com/users/Unibeautify/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Unibeautify/unibeautify-cli","description":"CLI for Unibeautify","fork":false,"url":"https://api.github.com/repos/Unibeautify/unibeautify-cli","forks_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/forks","keys_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/teams","hooks_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/hooks","issue_events_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/events{/number}","events_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/events","assignees_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/assignees{/user}","branches_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/branches{/branch}","tags_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/tags","blobs_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/languages","stargazers_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/stargazers","contributors_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/contributors","subscribers_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/subscribers","subscription_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/subscription","commits_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/contents/{+path}","compare_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/merges","archive_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/downloads","issues_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues{/number}","pulls_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/labels{/name}","releases_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/releases{/id}","deployments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/deployments","created_at":"2016-08-06T02:58:12Z","updated_at":"2018-11-06T00:21:48Z","pushed_at":"2018-11-06T17:12:23Z","git_url":"git://github.com/Unibeautify/unibeautify-cli.git","ssh_url":"git@github.com:Unibeautify/unibeautify-cli.git","clone_url":"https://github.com/Unibeautify/unibeautify-cli.git","svn_url":"https://github.com/Unibeautify/unibeautify-cli","homepage":"https://github.com/unibeautify/unibeautify","size":530,"stargazers_count":15,"watchers_count":15,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":13,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":3,"open_issues":13,"watchers":15,"default_branch":"master"}},"base":{"label":"Unibeautify:master","ref":"master","sha":"d6e090bbe2dcbb0bb99f8fb9e2703a6593900b39","user":{"login":"Unibeautify","id":21251312,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjUxMzEy","avatar_url":"https://avatars3.githubusercontent.com/u/21251312?v=4","gravatar_id":"","url":"https://api.github.com/users/Unibeautify","html_url":"https://github.com/Unibeautify","followers_url":"https://api.github.com/users/Unibeautify/followers","following_url":"https://api.github.com/users/Unibeautify/following{/other_user}","gists_url":"https://api.github.com/users/Unibeautify/gists{/gist_id}","starred_url":"https://api.github.com/users/Unibeautify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unibeautify/subscriptions","organizations_url":"https://api.github.com/users/Unibeautify/orgs","repos_url":"https://api.github.com/users/Unibeautify/repos","events_url":"https://api.github.com/users/Unibeautify/events{/privacy}","received_events_url":"https://api.github.com/users/Unibeautify/received_events","type":"Organization","site_admin":false},"repo":{"id":65061973,"node_id":"MDEwOlJlcG9zaXRvcnk2NTA2MTk3Mw==","name":"unibeautify-cli","full_name":"Unibeautify/unibeautify-cli","private":false,"owner":{"login":"Unibeautify","id":21251312,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIxMjUxMzEy","avatar_url":"https://avatars3.githubusercontent.com/u/21251312?v=4","gravatar_id":"","url":"https://api.github.com/users/Unibeautify","html_url":"https://github.com/Unibeautify","followers_url":"https://api.github.com/users/Unibeautify/followers","following_url":"https://api.github.com/users/Unibeautify/following{/other_user}","gists_url":"https://api.github.com/users/Unibeautify/gists{/gist_id}","starred_url":"https://api.github.com/users/Unibeautify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Unibeautify/subscriptions","organizations_url":"https://api.github.com/users/Unibeautify/orgs","repos_url":"https://api.github.com/users/Unibeautify/repos","events_url":"https://api.github.com/users/Unibeautify/events{/privacy}","received_events_url":"https://api.github.com/users/Unibeautify/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Unibeautify/unibeautify-cli","description":"CLI for Unibeautify","fork":false,"url":"https://api.github.com/repos/Unibeautify/unibeautify-cli","forks_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/forks","keys_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/teams","hooks_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/hooks","issue_events_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/events{/number}","events_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/events","assignees_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/assignees{/user}","branches_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/branches{/branch}","tags_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/tags","blobs_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/languages","stargazers_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/stargazers","contributors_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/contributors","subscribers_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/subscribers","subscription_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/subscription","commits_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/contents/{+path}","compare_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/merges","archive_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/downloads","issues_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues{/number}","pulls_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/labels{/name}","releases_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/releases{/id}","deployments_url":"https://api.github.com/repos/Unibeautify/unibeautify-cli/deployments","created_at":"2016-08-06T02:58:12Z","updated_at":"2018-11-06T00:21:48Z","pushed_at":"2018-11-06T17:12:23Z","git_url":"git://github.com/Unibeautify/unibeautify-cli.git","ssh_url":"git@github.com:Unibeautify/unibeautify-cli.git","clone_url":"https://github.com/Unibeautify/unibeautify-cli.git","svn_url":"https://github.com/Unibeautify/unibeautify-cli","homepage":"https://github.com/unibeautify/unibeautify","size":530,"stargazers_count":15,"watchers_count":15,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":13,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":3,"open_issues":13,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116"},"html":{"href":"https://github.com/Unibeautify/unibeautify-cli/pull/116"},"issue":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/116"},"comments":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/Unibeautify/unibeautify-cli/statuses/c6766f8924a7b3b712cb0d7ca76292b52b10452f"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Glavin001"}}