{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments/49755704","id":49755704,"diff_hunk":"@@ -0,0 +1,281 @@\n+﻿#if PSCMDLET_HELP\n+using Microsoft.CLU.Common;\n+using Microsoft.CLU.Metadata;\n+using Microsoft.CLU.Common.Properties;\n+using System;\n+using System.Collections.Generic;\n+using System.IO;\n+using System.Linq;\n+using System.Management.Automation;\n+using System.Text;\n+\n+namespace Microsoft.CLU.Help\n+{\n+    /// <summary>\n+    /// Generates Cmdlet command help.\n+    /// </summary>\n+    internal static class CmdletHelp\n+    {\n+        /// <summary>\n+        /// Generates a list of text lines containing help information for a specific Cmdlet command.\n+        /// </summary>\n+        /// <param name=\"format\">The command help formattter</param>\n+        /// <param name=\"args\">The command-line arguments to be considered in the help logic.</param>\n+        /// <param name=\"prefix\">True if the help argument comes first, false if last.</param>\n+        /// <returns>A list of lines containing help information.</returns>\n+        /// <remarks>\n+        /// This should be called for generating help for a commands, for example,\n+        /// \n+        ///     azure help vm start     (prefix = true)\n+        /// \n+        /// In the prefix form, if the arguments provide sufficient detail to identify a single command, \n+        /// the details about that command are listed. If more than one command is found, they are listed.\n+        /// \n+        ///     azure vm start --help   (prefix = false)\n+        ///\n+        /// In the postfix form, there will never be a command list. Rather, if the arguments match an\n+        /// existing command, help for only that command is displayed. If none match the arguments exactly,\n+        /// an error is generated.\n+        /// </remarks>\n+        public static IEnumerable<string> Generate(Func<string, string, bool, bool, string> format, IEnumerable<string> modules, string[] arguments, bool prefix)\n+        {\n+            var result = new List<string>();\n+\n+            var matches = FindMatches(modules, arguments);\n+\n+            if (matches != null)\n+            {\n+                var cmdlets = matches.SelectMany(m => m.Cmdlets).ToArray();\n+\n+                if (cmdlets.Length == 1)\n+                {\n+                    GenerateSingleCommandHelp(format, result, cmdlets[0]);\n+                    return result;\n+                }\n+                else if (prefix)\n+                {\n+                    GenerateCommandList(result, cmdlets);\n+                    return result;\n+                }\n+                else\n+                {\n+                    foreach (var cmdlet in cmdlets)\n+                    {\n+                        if (cmdlet.Keys.Split(Constants.CmdletIndexWordSeparator[0]).Length == arguments.Length)\n+                        {\n+                            GenerateSingleCommandHelp(format, result, cmdlet);\n+                            return result;\n+                        }\n+                    }\n+                }\n+            }\n+\n+            return new string[] { string.Format(Strings.CmdletHelp_Generate_NoCommandAvailable, CLUEnvironment.ScriptName, string.Join(\" \", arguments)) };\n+        }\n+\n+        private static void GenerateCommandList(List<string> result, InstalledCmdletInfo[] cmdlets)\n+        {\n+            var longest = cmdlets\n+                .Select(c => new { Name = $\"{CLUEnvironment.ScriptName} {c.Keys.Replace(Constants.CmdletIndexWordSeparator[0], ' ')}\", Brief = c.Info.Brief })\n+                .Select(n => n.Name.Length).Max<int>();\n+\n+            foreach (var cmdlet in cmdlets)\n+            {\n+                var bldr = new StringBuilder();\n+                var name = $\"{CLUEnvironment.ScriptName} {cmdlet.Keys.Replace(Constants.CmdletIndexWordSeparator[0], ' ')}\";\n+                bldr.Append(name);\n+                bldr.Append(new String(' ', longest - name.Length + 1));\n+                bldr.Append(cmdlet.Info.Brief);\n+                result.Add(bldr.ToString());\n+            }\n+        }\n+\n+        private static void GenerateSingleCommandHelp(Func<string, string, bool, bool, string> formatter, List<string> result, InstalledCmdletInfo cmdlet)\n+        {\n+            var info = cmdlet.Info;\n+\n+            if (string.IsNullOrEmpty(info.Brief))\n+            {\n+                result.Add(\"\");\n+                result.Add($\"{info.Name}\");\n+            }\n+            else\n+            {\n+                result.Add(\"\");\n+                result.Add($\"{info.Name}: {info.Brief}\");\n+            }\n+\n+            if (info.Description.Count > 0)\n+            {\n+                result.Add(\"\");\n+\n+                foreach (var descLine in info.Description)\n+                {\n+                    result.Add(\"\");\n+                    result.Add($\"{descLine}\");\n+                }\n+            }\n+\n+            result.Add(\"\");\n+            result.Add(\"\");\n+            result.Add(Strings.CmdletHelp_GenerateSingleCommandHelp_TxtCommandSyntax);\n+\n+            var parameters = new Dictionary<string, MAMLReader.ParameterHelpInfo>();\n+\n+            foreach (var pset in info.ParameterSets)\n+            {\n+                result.Add(\"\");\n+\n+                var builder = new System.Text.StringBuilder();\n+                builder.Append(CLUEnvironment.ScriptName).Append(' ').Append(info.Keys.Replace(';', ' '));\n+\n+                foreach (var p in pset.Parameters)\n+                {\n+                    if (!parameters.ContainsKey(p.Name))\n+                        parameters.Add(p.Name, p);\n+                    var formattedName = formatter(p.Name, MapTypeName(p.Type), p.IsMandatory, p.Position != int.MaxValue);\n+                    builder.Append(' ').Append(formattedName);\n+                }\n+                result.Add(builder.ToString());\n+            }\n+\n+            AddReflectionParameterInfo(cmdlet, parameters);\n+\n+            if (parameters.Values.Count > 0)\n+            {\n+                result.Add(\"\");\n+                result.Add(\"\");\n+                result.Add(Strings.CmdletHelp_GenerateSingleCommandHelp_TxtParameters);\n+                result.Add(\"\");\n+\n+                bool hasDescriptions = parameters.Values.SelectMany(p => p.Description).Any();\n+\n+                foreach (var p in parameters.Values)\n+                {\n+                    var bldr = new StringBuilder(formatter(p.Name, null, true, false));\n+                    var aliases = p.Aliases != null ? string.Join(\", \", p.Aliases.Select(a => formatter(a, null, true, false))) : null;","path":"src/CLU/Microsoft.CLU/Extensions/Help/CmdletHelp.cs","position":156,"original_position":156,"commit_id":"ea08140d8ad57db032a142429de8a6766c5bdffd","original_commit_id":"ea08140d8ad57db032a142429de8a6766c5bdffd","user":{"login":"markcowl","id":1054056,"avatar_url":"https://avatars.githubusercontent.com/u/1054056?v=3","gravatar_id":"","url":"https://api.github.com/users/markcowl","html_url":"https://github.com/markcowl","followers_url":"https://api.github.com/users/markcowl/followers","following_url":"https://api.github.com/users/markcowl/following{/other_user}","gists_url":"https://api.github.com/users/markcowl/gists{/gist_id}","starred_url":"https://api.github.com/users/markcowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markcowl/subscriptions","organizations_url":"https://api.github.com/users/markcowl/orgs","repos_url":"https://api.github.com/users/markcowl/repos","events_url":"https://api.github.com/users/markcowl/events{/privacy}","received_events_url":"https://api.github.com/users/markcowl/received_events","type":"User","site_admin":false},"body":"line breaks","created_at":"2016-01-14T17:23:12Z","updated_at":"2016-01-14T17:23:12Z","html_url":"https://github.com/Azure/azure-powershell/pull/1643#discussion_r49755704","pull_request_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments/49755704"},"html":{"href":"https://github.com/Azure/azure-powershell/pull/1643#discussion_r49755704"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643","id":55956804,"html_url":"https://github.com/Azure/azure-powershell/pull/1643","diff_url":"https://github.com/Azure/azure-powershell/pull/1643.diff","patch_url":"https://github.com/Azure/azure-powershell/pull/1643.patch","issue_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1643","number":1643,"state":"open","locked":false,"title":"added changes for clu help files","user":{"login":"arroyc","id":16231002,"avatar_url":"https://avatars.githubusercontent.com/u/16231002?v=3","gravatar_id":"","url":"https://api.github.com/users/arroyc","html_url":"https://github.com/arroyc","followers_url":"https://api.github.com/users/arroyc/followers","following_url":"https://api.github.com/users/arroyc/following{/other_user}","gists_url":"https://api.github.com/users/arroyc/gists{/gist_id}","starred_url":"https://api.github.com/users/arroyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arroyc/subscriptions","organizations_url":"https://api.github.com/users/arroyc/orgs","repos_url":"https://api.github.com/users/arroyc/repos","events_url":"https://api.github.com/users/arroyc/events{/privacy}","received_events_url":"https://api.github.com/users/arroyc/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-13T21:16:39Z","updated_at":"2016-01-14T17:23:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30df4e7cb5a7603277562f045da9a75888de373c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1643/comments","statuses_url":"https://api.github.com/repos/Azure/azure-powershell/statuses/ea08140d8ad57db032a142429de8a6766c5bdffd","head":{"label":"arroyc:clu","ref":"clu","sha":"ea08140d8ad57db032a142429de8a6766c5bdffd","user":{"login":"arroyc","id":16231002,"avatar_url":"https://avatars.githubusercontent.com/u/16231002?v=3","gravatar_id":"","url":"https://api.github.com/users/arroyc","html_url":"https://github.com/arroyc","followers_url":"https://api.github.com/users/arroyc/followers","following_url":"https://api.github.com/users/arroyc/following{/other_user}","gists_url":"https://api.github.com/users/arroyc/gists{/gist_id}","starred_url":"https://api.github.com/users/arroyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arroyc/subscriptions","organizations_url":"https://api.github.com/users/arroyc/orgs","repos_url":"https://api.github.com/users/arroyc/repos","events_url":"https://api.github.com/users/arroyc/events{/privacy}","received_events_url":"https://api.github.com/users/arroyc/received_events","type":"User","site_admin":false},"repo":{"id":49601660,"name":"azure-powershell","full_name":"arroyc/azure-powershell","owner":{"login":"arroyc","id":16231002,"avatar_url":"https://avatars.githubusercontent.com/u/16231002?v=3","gravatar_id":"","url":"https://api.github.com/users/arroyc","html_url":"https://github.com/arroyc","followers_url":"https://api.github.com/users/arroyc/followers","following_url":"https://api.github.com/users/arroyc/following{/other_user}","gists_url":"https://api.github.com/users/arroyc/gists{/gist_id}","starred_url":"https://api.github.com/users/arroyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arroyc/subscriptions","organizations_url":"https://api.github.com/users/arroyc/orgs","repos_url":"https://api.github.com/users/arroyc/repos","events_url":"https://api.github.com/users/arroyc/events{/privacy}","received_events_url":"https://api.github.com/users/arroyc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arroyc/azure-powershell","description":"Microsoft Azure PowerShell","fork":true,"url":"https://api.github.com/repos/arroyc/azure-powershell","forks_url":"https://api.github.com/repos/arroyc/azure-powershell/forks","keys_url":"https://api.github.com/repos/arroyc/azure-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arroyc/azure-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arroyc/azure-powershell/teams","hooks_url":"https://api.github.com/repos/arroyc/azure-powershell/hooks","issue_events_url":"https://api.github.com/repos/arroyc/azure-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/arroyc/azure-powershell/events","assignees_url":"https://api.github.com/repos/arroyc/azure-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/arroyc/azure-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/arroyc/azure-powershell/tags","blobs_url":"https://api.github.com/repos/arroyc/azure-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arroyc/azure-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arroyc/azure-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/arroyc/azure-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arroyc/azure-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/arroyc/azure-powershell/languages","stargazers_url":"https://api.github.com/repos/arroyc/azure-powershell/stargazers","contributors_url":"https://api.github.com/repos/arroyc/azure-powershell/contributors","subscribers_url":"https://api.github.com/repos/arroyc/azure-powershell/subscribers","subscription_url":"https://api.github.com/repos/arroyc/azure-powershell/subscription","commits_url":"https://api.github.com/repos/arroyc/azure-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/arroyc/azure-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/arroyc/azure-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/arroyc/azure-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/arroyc/azure-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/arroyc/azure-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arroyc/azure-powershell/merges","archive_url":"https://api.github.com/repos/arroyc/azure-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arroyc/azure-powershell/downloads","issues_url":"https://api.github.com/repos/arroyc/azure-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/arroyc/azure-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/arroyc/azure-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/arroyc/azure-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arroyc/azure-powershell/labels{/name}","releases_url":"https://api.github.com/repos/arroyc/azure-powershell/releases{/id}","created_at":"2016-01-13T21:04:09Z","updated_at":"2016-01-13T21:04:29Z","pushed_at":"2016-01-13T21:16:08Z","git_url":"git://github.com/arroyc/azure-powershell.git","ssh_url":"git@github.com:arroyc/azure-powershell.git","clone_url":"https://github.com/arroyc/azure-powershell.git","svn_url":"https://github.com/arroyc/azure-powershell","homepage":null,"size":166210,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"Azure:clu","ref":"clu","sha":"9922ce324a351513edc54e7f2fc694d8dd9901e4","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":23891194,"name":"azure-powershell","full_name":"Azure/azure-powershell","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-powershell","description":"Microsoft Azure PowerShell","fork":false,"url":"https://api.github.com/repos/Azure/azure-powershell","forks_url":"https://api.github.com/repos/Azure/azure-powershell/forks","keys_url":"https://api.github.com/repos/Azure/azure-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-powershell/teams","hooks_url":"https://api.github.com/repos/Azure/azure-powershell/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-powershell/events","assignees_url":"https://api.github.com/repos/Azure/azure-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-powershell/tags","blobs_url":"https://api.github.com/repos/Azure/azure-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-powershell/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-powershell/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-powershell/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-powershell/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-powershell/subscription","commits_url":"https://api.github.com/repos/Azure/azure-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-powershell/merges","archive_url":"https://api.github.com/repos/Azure/azure-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-powershell/downloads","issues_url":"https://api.github.com/repos/Azure/azure-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-powershell/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-powershell/releases{/id}","created_at":"2014-09-10T20:35:18Z","updated_at":"2016-01-14T04:42:59Z","pushed_at":"2016-01-14T17:10:25Z","git_url":"git://github.com/Azure/azure-powershell.git","ssh_url":"git@github.com:Azure/azure-powershell.git","clone_url":"https://github.com/Azure/azure-powershell.git","svn_url":"https://github.com/Azure/azure-powershell","homepage":null,"size":170234,"stargazers_count":349,"watchers_count":349,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":332,"mirror_url":null,"open_issues_count":336,"forks":332,"open_issues":336,"watchers":349,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643"},"html":{"href":"https://github.com/Azure/azure-powershell/pull/1643"},"issue":{"href":"https://api.github.com/repos/Azure/azure-powershell/issues/1643"},"comments":{"href":"https://api.github.com/repos/Azure/azure-powershell/issues/1643/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/1643/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-powershell/statuses/ea08140d8ad57db032a142429de8a6766c5bdffd"}}}}