{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/23643879","id":23643879,"diff_hunk":"@@ -67,4 +73,93 @@ public String getPattern() {\n   public String getDescription() {\n     return \"Prints this helper text\";\n   }\n+\n+  /**\n+   * Prints the given command pattern which wrap at the given column width. It prints on multiple lines like this:\n+   *\n+   * <pre>{@code\n+   * command sub-command <arg1> <arg2>\n+   *                     <arg3> [<optiona-long-arg4>]\n+   * }\n+   * </pre>\n+   *\n+   * @param pattern the command pattern to print\n+   * @param output the {@link PrintStream} to write to\n+   * @param colWidth width of the column\n+   */\n+  private void printPattern(String pattern, PrintStream output, int colWidth) {\n+    if (pattern.length() <= colWidth) {\n+      output.println(pattern);\n+      return;\n+    }\n+\n+    // Find the first <argument>, it is used for alignment in 2nd line and onward.\n+    int startIdx = pattern.indexOf('<');\n+    // If no '<', it shouldn't reach here (they should be short command). If it does, just print it.\n+    if (startIdx < 0) {\n+      output.println(pattern);\n+      return;\n+    }\n+\n+    // First line should at least includes the first <argument>\n+    int idx = pattern.lastIndexOf('>', colWidth) + 1;\n+    if (idx <= 0) {\n+      idx = pattern.indexOf('>', startIdx) + 1;\n+      if (idx <= 0) {\n+        idx = pattern.length();\n+      }\n+    }\n+    // Make sure we includes the closing ] of optional argument\n+    if (idx < pattern.length() && pattern.charAt(idx) == ']') {\n+      idx++;\n+    }\n+    output.println(pattern.substring(0, idx));\n+\n+    if ((idx + 1) < pattern.length()) {\n+      // For rest of the line, align them to the startIdx\n+      wrappedPrint(pattern.substring(idx + 1), output, colWidth, startIdx);\n+    }\n+  }\n+\n+  /**\n+   * Prints the given string with auto line wrapping at the given column width.","path":"cdap-cli/src/main/java/co/cask/cdap/cli/command/HelpCommand.java","position":89,"original_position":89,"commit_id":"9f3f67f394e4af4fe0cf1e99b4fc1d803f268530","original_commit_id":"9f3f67f394e4af4fe0cf1e99b4fc1d803f268530","user":{"login":"awholegunch","id":6394794,"avatar_url":"https://avatars.githubusercontent.com/u/6394794?v=3","gravatar_id":"","url":"https://api.github.com/users/awholegunch","html_url":"https://github.com/awholegunch","followers_url":"https://api.github.com/users/awholegunch/followers","following_url":"https://api.github.com/users/awholegunch/following{/other_user}","gists_url":"https://api.github.com/users/awholegunch/gists{/gist_id}","starred_url":"https://api.github.com/users/awholegunch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awholegunch/subscriptions","organizations_url":"https://api.github.com/users/awholegunch/orgs","repos_url":"https://api.github.com/users/awholegunch/repos","events_url":"https://api.github.com/users/awholegunch/events{/privacy}","received_events_url":"https://api.github.com/users/awholegunch/received_events","type":"User","site_admin":false},"body":"Prints the given string with text wrapping at the given column width.","created_at":"2015-01-27T21:20:30Z","updated_at":"2015-01-27T21:20:30Z","html_url":"https://github.com/caskdata/cdap/pull/1138#discussion_r23643879","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/1138","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/23643879"},"html":{"href":"https://github.com/caskdata/cdap/pull/1138#discussion_r23643879"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1138"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/1138","id":28141571,"html_url":"https://github.com/caskdata/cdap/pull/1138","diff_url":"https://github.com/caskdata/cdap/pull/1138.diff","patch_url":"https://github.com/caskdata/cdap/pull/1138.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/1138","number":1138,"state":"open","locked":false,"title":"Better formatting for the CLI help output with auto-line wrap and alignment","user":{"login":"chtyim","id":885032,"avatar_url":"https://avatars.githubusercontent.com/u/885032?v=3","gravatar_id":"","url":"https://api.github.com/users/chtyim","html_url":"https://github.com/chtyim","followers_url":"https://api.github.com/users/chtyim/followers","following_url":"https://api.github.com/users/chtyim/following{/other_user}","gists_url":"https://api.github.com/users/chtyim/gists{/gist_id}","starred_url":"https://api.github.com/users/chtyim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chtyim/subscriptions","organizations_url":"https://api.github.com/users/chtyim/orgs","repos_url":"https://api.github.com/users/chtyim/repos","events_url":"https://api.github.com/users/chtyim/events{/privacy}","received_events_url":"https://api.github.com/users/chtyim/received_events","type":"User","site_admin":false},"body":"This is some sample output\r\n\r\n```\r\ncall service <app-id.service-id> <http-method> <endpoint> [headers <headers>]\r\n             [body <body>]\r\n  Calls a Service endpoint. The header is formatted as \"{'key':'value', ...}\"\r\n  and the body is a String.\r\n\r\nconnect <cdap-instance-uri>\r\n  Connects to a CDAP instance. <credential(s)> parameter(s) could be used if\r\n  authentication is enabled in the gateway server.\r\n\r\ncreate adapter <adapter-name> type <adapter-type> [props <adapter-props>]\r\n               src <adapter-source> [src-props <adapter-source-config>] sink\r\n               <adapter-sink> [sink-props <adapter-sink-config>]\r\n  Creates a Adapter\r\n\r\nget spark status <app-id.spark-id>\r\n  Gets the status of a Spark\r\n\r\nget stream <stream-id> [<start-time>] [<end-time>] [<limit>]\r\n  Gets events from a Stream. The time format for <start-time> and <end-time> can\r\n  be a timestamp in milliseconds or a relative time in the form of\r\n  [+|-][0-9][d|h|m|s]. <start-time> is relative to current time; <end-time>, it\r\n  is relative to start time. Special constants \"min\" and \"max\" can also be used\r\n  to represent \"0\" and \"max timestamp\" respectively.\r\n\r\nget workflow preferences [<app-id.workflow-id>]\r\n  Gets the preferences of a Workflow\r\n```","created_at":"2015-01-27T20:27:31Z","updated_at":"2015-01-27T21:20:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1deef6e219cb3592ff51f430cdf6f2d925184f2","assignee":null,"milestone":{"url":"https://api.github.com/repos/caskdata/cdap/milestones/2","labels_url":"https://api.github.com/repos/caskdata/cdap/milestones/2/labels","id":880401,"number":2,"title":"2.7.0","description":null,"creator":{"login":"jwang47","id":1084704,"avatar_url":"https://avatars.githubusercontent.com/u/1084704?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang47","html_url":"https://github.com/jwang47","followers_url":"https://api.github.com/users/jwang47/followers","following_url":"https://api.github.com/users/jwang47/following{/other_user}","gists_url":"https://api.github.com/users/jwang47/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang47/subscriptions","organizations_url":"https://api.github.com/users/jwang47/orgs","repos_url":"https://api.github.com/users/jwang47/repos","events_url":"https://api.github.com/users/jwang47/events{/privacy}","received_events_url":"https://api.github.com/users/jwang47/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":108,"state":"open","created_at":"2014-11-25T19:54:18Z","updated_at":"2015-01-27T21:13:47Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/1138/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/1138/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/1138/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/9f3f67f394e4af4fe0cf1e99b4fc1d803f268530","head":{"label":"caskdata:hotfix/better-cli-help","ref":"hotfix/better-cli-help","sha":"9f3f67f394e4af4fe0cf1e99b4fc1d803f268530","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-27T09:54:12Z","pushed_at":"2015-01-27T21:15:12Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":706385,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":16,"forks":7,"open_issues":16,"watchers":23,"default_branch":"develop"}},"base":{"label":"caskdata:release/2.7.0","ref":"release/2.7.0","sha":"93ea356a610f9d8a1b334c52149b9d796dc13c67","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-27T09:54:12Z","pushed_at":"2015-01-27T21:15:12Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":706385,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":16,"forks":7,"open_issues":16,"watchers":23,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1138"},"html":{"href":"https://github.com/caskdata/cdap/pull/1138"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1138"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/1138/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1138/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/1138/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/9f3f67f394e4af4fe0cf1e99b4fc1d803f268530"}}}}