{"action":"created","comment":{"url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/comments/92521427","pull_request_review_id":13038477,"id":92521427,"diff_hunk":"@@ -0,0 +1,125 @@\n+<?php\n+\n+namespace Blacksmith\\Commands\\Make;\n+\n+use Blacksmith\\Command;\n+\n+/**\n+ * The \"Make Command\" Command.\n+ *\n+ * This command is responsible for creating new commands that will be placed in\n+ * the commands directory in the target project's main directory. If provided \n+ * subdirectories to create the command in, the CmdCommand class will place the\n+ * new command in those subdirectories.\n+ */\n+\n+class CmdCommand extends Command {\n+\n+    // Set the signature for the command\n+    const signature       = 'make:cmd';\n+\n+    // Set the description of the command\n+    const description     = 'Creates a new command';\n+\n+    /**\n+     * The full path for the new command.\n+     * @var string\n+     */\n+    protected $command_dir_path = '';\n+\n+    /**\n+     * Main method that will run the\n+     * command operation.\n+     */\n+    public function run()\n+    {\n+        // Validate argument was passed\n+        if (empty($this->getArguments())) {\n+            $this->console->output->alert('make:cmd requires an argument.');\n+            return;\n+        }\n+\n+        $this->createCommand();\n+    }\n+\n+    /**\n+     * Create a new command.\n+     *\n+     * Gets the provided arguments and creates subdirectories if they do not already exist\n+     * for the provided command. The last element in the chain of subdirectories is treated\n+     * as the name of the callabale command, in which we create a template command file for.\n+     *\n+     * For example:\n+     *\n+     *      php blacksmith make:cmd this:is:my:command\n+     *\n+     * results in the following path being created:\n+     *\n+     *      my-project/commands/this/is/my/Command.php\n+     */\n+    protected function createCommand()\n+    {\n+        $arg = $this->getArguments()[0];\n+\n+        $sub_dir_names = explode(DIRECTORY_SEPARATOR, $arg);\n+        $command_name  = $sub_dir_names[count($sub_dir_names) - 1];\n+\n+        // Remove the command name from the list of sub dirs\n+        unset($sub_dir_names[count($sub_dir_names) - 1]);\n+\n+        $this->createSubDirectories($sub_dir_names);\n+        $this->createCommandFile($command_name);\n+    }\n+\n+    /**\n+     * Create the subdirectories for the new command.\n+     *\n+     * @param array $sub_dirs\n+     *      The array of subdirectory names to create for the new command.\n+     */\n+    protected function createSubDirectories(array $sub_dirs)\n+    {\n+        // Get the path to the /commands folder\n+        $blacksmith_cmd_dir = BLACKSMITH_ROOT . BLACKSMITH_COMMANDS_DIR;\n+\n+        // Form the full path with sub dirs for the new command\n+        // e.g. \"my-project/commands/my/new/Cmd.php\"\n+        $this->command_dir_path = $blacksmith_cmd_dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $sub_dirs);\n+\n+        if (!file_exists($this->command_dir_path)) {\n+            mkdir($this->command_dir_path, 0755, true);\n+        }\n+    }\n+\n+    /**\n+     * Create the .php file for the new command.\n+     *\n+     * @param string $command_name\n+     *      The name of the new command to create the command file for.\n+     */\n+    protected function createCommandFile($command_name)\n+    {\n+        // Check if the command already has the .php extension\n+        $file_extension = strtolower(pathinfo($command_name, PATHINFO_EXTENSION));\n+\n+        if ($file_extension !== 'php') {\n+            $command_name .= '.php';\n+        }\n+\n+        $command_file_name      = ucfirst($command_name);\n+        $command_file_full_path = $this->command_dir_path . DIRECTORY_SEPARATOR . $command_file_name;\n+\n+        // Check if the command already exists\n+        if (file_exists($command_file_full_path)) {\n+            $this->console->output->alert('Command already exists.');\n+            return;\n+        }\n+\n+        // Create the file for the new command\n+        fopen($command_file_full_path, 'w');","path":"src/Commands/make/CmdCommand.php","position":119,"original_position":119,"commit_id":"3779e2d8f39e274542d95b1505cb34747a041b59","original_commit_id":"3779e2d8f39e274542d95b1505cb34747a041b59","user":{"login":"grahamsutt12","id":7832785,"avatar_url":"https://avatars.githubusercontent.com/u/7832785?v=3","gravatar_id":"","url":"https://api.github.com/users/grahamsutt12","html_url":"https://github.com/grahamsutt12","followers_url":"https://api.github.com/users/grahamsutt12/followers","following_url":"https://api.github.com/users/grahamsutt12/following{/other_user}","gists_url":"https://api.github.com/users/grahamsutt12/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamsutt12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamsutt12/subscriptions","organizations_url":"https://api.github.com/users/grahamsutt12/orgs","repos_url":"https://api.github.com/users/grahamsutt12/repos","events_url":"https://api.github.com/users/grahamsutt12/events{/privacy}","received_events_url":"https://api.github.com/users/grahamsutt12/received_events","type":"User","site_admin":false},"body":"So I looked into `fopen` a little bit more and learned that `fopen` only generates a warning if it fails to write and that an opened file will get closed at script termination. With that in mind, it still is best practice to use `fclose` to close it manually, so I'll be adding that fix.\r\n\r\nI also wrapped that in a try/catch and will be throwing an error if the command being created already exists, which will be caught so an alert message can be printed to the console.","created_at":"2016-12-15T00:26:45Z","updated_at":"2016-12-15T00:26:45Z","html_url":"https://github.com/eaperezc/blacksmith/pull/4#discussion_r92521427","pull_request_url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/comments/92521427"},"html":{"href":"https://github.com/eaperezc/blacksmith/pull/4#discussion_r92521427"},"pull_request":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4","id":97894162,"html_url":"https://github.com/eaperezc/blacksmith/pull/4","diff_url":"https://github.com/eaperezc/blacksmith/pull/4.diff","patch_url":"https://github.com/eaperezc/blacksmith/pull/4.patch","issue_url":"https://api.github.com/repos/eaperezc/blacksmith/issues/4","number":4,"state":"open","locked":false,"title":"Added the make:cmd file and ability to create subdirectories and comm…","user":{"login":"grahamsutt12","id":7832785,"avatar_url":"https://avatars.githubusercontent.com/u/7832785?v=3","gravatar_id":"","url":"https://api.github.com/users/grahamsutt12","html_url":"https://github.com/grahamsutt12","followers_url":"https://api.github.com/users/grahamsutt12/followers","following_url":"https://api.github.com/users/grahamsutt12/following{/other_user}","gists_url":"https://api.github.com/users/grahamsutt12/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamsutt12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamsutt12/subscriptions","organizations_url":"https://api.github.com/users/grahamsutt12/orgs","repos_url":"https://api.github.com/users/grahamsutt12/repos","events_url":"https://api.github.com/users/grahamsutt12/events{/privacy}","received_events_url":"https://api.github.com/users/grahamsutt12/received_events","type":"User","site_admin":false},"body":"…and file when providing a new command.\r\n\r\nYou should be able to perform the following command now:\r\n\r\n```bash\r\n$ php blacksmith make:cmd my/new/command\r\n```\r\n\r\nAnd consequentially a file should be generated in the respective subdirectories:\r\n\r\n```\r\nsome-project/commands/my/new/Command.php\r\n```\r\n\r\nNote: The name of the command will be the new name of the file but with a capital letter.\r\n\r\n**Other Misc. Changes**\r\n\r\n* Made use of `DIRECTORY_SEPARATOR` constant so that file paths can be OS agnostic. We should probably update some of the other places in the app to use it, too.\r\n* Added a new `success` message in the `Output.php` class that prints a green message with transparent background to the console.\r\n* Running `make:cmd` command will actually create the `/commands` folder recursively if it doesn't yet exist, so we may actually be able to remove it from the `bootstrap` file.\r\n","created_at":"2016-12-14T06:24:50Z","updated_at":"2016-12-15T00:26:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"166b823ea85efa1768a7e1493a0b34a08696c536","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4/commits","review_comments_url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4/comments","review_comment_url":"https://api.github.com/repos/eaperezc/blacksmith/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eaperezc/blacksmith/issues/4/comments","statuses_url":"https://api.github.com/repos/eaperezc/blacksmith/statuses/3779e2d8f39e274542d95b1505cb34747a041b59","head":{"label":"grahamsutt12:master","ref":"master","sha":"3779e2d8f39e274542d95b1505cb34747a041b59","user":{"login":"grahamsutt12","id":7832785,"avatar_url":"https://avatars.githubusercontent.com/u/7832785?v=3","gravatar_id":"","url":"https://api.github.com/users/grahamsutt12","html_url":"https://github.com/grahamsutt12","followers_url":"https://api.github.com/users/grahamsutt12/followers","following_url":"https://api.github.com/users/grahamsutt12/following{/other_user}","gists_url":"https://api.github.com/users/grahamsutt12/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamsutt12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamsutt12/subscriptions","organizations_url":"https://api.github.com/users/grahamsutt12/orgs","repos_url":"https://api.github.com/users/grahamsutt12/repos","events_url":"https://api.github.com/users/grahamsutt12/events{/privacy}","received_events_url":"https://api.github.com/users/grahamsutt12/received_events","type":"User","site_admin":false},"repo":{"id":76271760,"name":"blacksmith","full_name":"grahamsutt12/blacksmith","owner":{"login":"grahamsutt12","id":7832785,"avatar_url":"https://avatars.githubusercontent.com/u/7832785?v=3","gravatar_id":"","url":"https://api.github.com/users/grahamsutt12","html_url":"https://github.com/grahamsutt12","followers_url":"https://api.github.com/users/grahamsutt12/followers","following_url":"https://api.github.com/users/grahamsutt12/following{/other_user}","gists_url":"https://api.github.com/users/grahamsutt12/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamsutt12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamsutt12/subscriptions","organizations_url":"https://api.github.com/users/grahamsutt12/orgs","repos_url":"https://api.github.com/users/grahamsutt12/repos","events_url":"https://api.github.com/users/grahamsutt12/events{/privacy}","received_events_url":"https://api.github.com/users/grahamsutt12/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/grahamsutt12/blacksmith","description":"PHP Command Line Interface helper library","fork":true,"url":"https://api.github.com/repos/grahamsutt12/blacksmith","forks_url":"https://api.github.com/repos/grahamsutt12/blacksmith/forks","keys_url":"https://api.github.com/repos/grahamsutt12/blacksmith/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grahamsutt12/blacksmith/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grahamsutt12/blacksmith/teams","hooks_url":"https://api.github.com/repos/grahamsutt12/blacksmith/hooks","issue_events_url":"https://api.github.com/repos/grahamsutt12/blacksmith/issues/events{/number}","events_url":"https://api.github.com/repos/grahamsutt12/blacksmith/events","assignees_url":"https://api.github.com/repos/grahamsutt12/blacksmith/assignees{/user}","branches_url":"https://api.github.com/repos/grahamsutt12/blacksmith/branches{/branch}","tags_url":"https://api.github.com/repos/grahamsutt12/blacksmith/tags","blobs_url":"https://api.github.com/repos/grahamsutt12/blacksmith/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grahamsutt12/blacksmith/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grahamsutt12/blacksmith/git/refs{/sha}","trees_url":"https://api.github.com/repos/grahamsutt12/blacksmith/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grahamsutt12/blacksmith/statuses/{sha}","languages_url":"https://api.github.com/repos/grahamsutt12/blacksmith/languages","stargazers_url":"https://api.github.com/repos/grahamsutt12/blacksmith/stargazers","contributors_url":"https://api.github.com/repos/grahamsutt12/blacksmith/contributors","subscribers_url":"https://api.github.com/repos/grahamsutt12/blacksmith/subscribers","subscription_url":"https://api.github.com/repos/grahamsutt12/blacksmith/subscription","commits_url":"https://api.github.com/repos/grahamsutt12/blacksmith/commits{/sha}","git_commits_url":"https://api.github.com/repos/grahamsutt12/blacksmith/git/commits{/sha}","comments_url":"https://api.github.com/repos/grahamsutt12/blacksmith/comments{/number}","issue_comment_url":"https://api.github.com/repos/grahamsutt12/blacksmith/issues/comments{/number}","contents_url":"https://api.github.com/repos/grahamsutt12/blacksmith/contents/{+path}","compare_url":"https://api.github.com/repos/grahamsutt12/blacksmith/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grahamsutt12/blacksmith/merges","archive_url":"https://api.github.com/repos/grahamsutt12/blacksmith/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grahamsutt12/blacksmith/downloads","issues_url":"https://api.github.com/repos/grahamsutt12/blacksmith/issues{/number}","pulls_url":"https://api.github.com/repos/grahamsutt12/blacksmith/pulls{/number}","milestones_url":"https://api.github.com/repos/grahamsutt12/blacksmith/milestones{/number}","notifications_url":"https://api.github.com/repos/grahamsutt12/blacksmith/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grahamsutt12/blacksmith/labels{/name}","releases_url":"https://api.github.com/repos/grahamsutt12/blacksmith/releases{/id}","deployments_url":"https://api.github.com/repos/grahamsutt12/blacksmith/deployments","created_at":"2016-12-12T15:54:24Z","updated_at":"2016-12-12T15:54:25Z","pushed_at":"2016-12-14T06:42:03Z","git_url":"git://github.com/grahamsutt12/blacksmith.git","ssh_url":"git@github.com:grahamsutt12/blacksmith.git","clone_url":"https://github.com/grahamsutt12/blacksmith.git","svn_url":"https://github.com/grahamsutt12/blacksmith","homepage":null,"size":522,"stargazers_count":0,"watchers_count":0,"language":"PHP","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":"master"}},"base":{"label":"eaperezc:master","ref":"master","sha":"2b7d15b0b08b3e416b23bad03078c4c61c320ce2","user":{"login":"eaperezc","id":739642,"avatar_url":"https://avatars.githubusercontent.com/u/739642?v=3","gravatar_id":"","url":"https://api.github.com/users/eaperezc","html_url":"https://github.com/eaperezc","followers_url":"https://api.github.com/users/eaperezc/followers","following_url":"https://api.github.com/users/eaperezc/following{/other_user}","gists_url":"https://api.github.com/users/eaperezc/gists{/gist_id}","starred_url":"https://api.github.com/users/eaperezc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eaperezc/subscriptions","organizations_url":"https://api.github.com/users/eaperezc/orgs","repos_url":"https://api.github.com/users/eaperezc/repos","events_url":"https://api.github.com/users/eaperezc/events{/privacy}","received_events_url":"https://api.github.com/users/eaperezc/received_events","type":"User","site_admin":false},"repo":{"id":76146228,"name":"blacksmith","full_name":"eaperezc/blacksmith","owner":{"login":"eaperezc","id":739642,"avatar_url":"https://avatars.githubusercontent.com/u/739642?v=3","gravatar_id":"","url":"https://api.github.com/users/eaperezc","html_url":"https://github.com/eaperezc","followers_url":"https://api.github.com/users/eaperezc/followers","following_url":"https://api.github.com/users/eaperezc/following{/other_user}","gists_url":"https://api.github.com/users/eaperezc/gists{/gist_id}","starred_url":"https://api.github.com/users/eaperezc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eaperezc/subscriptions","organizations_url":"https://api.github.com/users/eaperezc/orgs","repos_url":"https://api.github.com/users/eaperezc/repos","events_url":"https://api.github.com/users/eaperezc/events{/privacy}","received_events_url":"https://api.github.com/users/eaperezc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eaperezc/blacksmith","description":"PHP Command Line Interface helper library","fork":false,"url":"https://api.github.com/repos/eaperezc/blacksmith","forks_url":"https://api.github.com/repos/eaperezc/blacksmith/forks","keys_url":"https://api.github.com/repos/eaperezc/blacksmith/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eaperezc/blacksmith/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eaperezc/blacksmith/teams","hooks_url":"https://api.github.com/repos/eaperezc/blacksmith/hooks","issue_events_url":"https://api.github.com/repos/eaperezc/blacksmith/issues/events{/number}","events_url":"https://api.github.com/repos/eaperezc/blacksmith/events","assignees_url":"https://api.github.com/repos/eaperezc/blacksmith/assignees{/user}","branches_url":"https://api.github.com/repos/eaperezc/blacksmith/branches{/branch}","tags_url":"https://api.github.com/repos/eaperezc/blacksmith/tags","blobs_url":"https://api.github.com/repos/eaperezc/blacksmith/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eaperezc/blacksmith/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eaperezc/blacksmith/git/refs{/sha}","trees_url":"https://api.github.com/repos/eaperezc/blacksmith/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eaperezc/blacksmith/statuses/{sha}","languages_url":"https://api.github.com/repos/eaperezc/blacksmith/languages","stargazers_url":"https://api.github.com/repos/eaperezc/blacksmith/stargazers","contributors_url":"https://api.github.com/repos/eaperezc/blacksmith/contributors","subscribers_url":"https://api.github.com/repos/eaperezc/blacksmith/subscribers","subscription_url":"https://api.github.com/repos/eaperezc/blacksmith/subscription","commits_url":"https://api.github.com/repos/eaperezc/blacksmith/commits{/sha}","git_commits_url":"https://api.github.com/repos/eaperezc/blacksmith/git/commits{/sha}","comments_url":"https://api.github.com/repos/eaperezc/blacksmith/comments{/number}","issue_comment_url":"https://api.github.com/repos/eaperezc/blacksmith/issues/comments{/number}","contents_url":"https://api.github.com/repos/eaperezc/blacksmith/contents/{+path}","compare_url":"https://api.github.com/repos/eaperezc/blacksmith/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eaperezc/blacksmith/merges","archive_url":"https://api.github.com/repos/eaperezc/blacksmith/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eaperezc/blacksmith/downloads","issues_url":"https://api.github.com/repos/eaperezc/blacksmith/issues{/number}","pulls_url":"https://api.github.com/repos/eaperezc/blacksmith/pulls{/number}","milestones_url":"https://api.github.com/repos/eaperezc/blacksmith/milestones{/number}","notifications_url":"https://api.github.com/repos/eaperezc/blacksmith/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eaperezc/blacksmith/labels{/name}","releases_url":"https://api.github.com/repos/eaperezc/blacksmith/releases{/id}","deployments_url":"https://api.github.com/repos/eaperezc/blacksmith/deployments","created_at":"2016-12-11T00:48:27Z","updated_at":"2016-12-14T03:37:39Z","pushed_at":"2016-12-14T06:42:44Z","git_url":"git://github.com/eaperezc/blacksmith.git","ssh_url":"git@github.com:eaperezc/blacksmith.git","clone_url":"https://github.com/eaperezc/blacksmith.git","svn_url":"https://github.com/eaperezc/blacksmith","homepage":null,"size":519,"stargazers_count":2,"watchers_count":2,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4"},"html":{"href":"https://github.com/eaperezc/blacksmith/pull/4"},"issue":{"href":"https://api.github.com/repos/eaperezc/blacksmith/issues/4"},"comments":{"href":"https://api.github.com/repos/eaperezc/blacksmith/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eaperezc/blacksmith/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/eaperezc/blacksmith/statuses/3779e2d8f39e274542d95b1505cb34747a041b59"}}}}
{"actor":{"display_login":"grahamsutt12"}}