{"action":"created","comment":{"url":"https://api.github.com/repos/titon/framework/pulls/comments/26091354","id":26091354,"diff_hunk":"@@ -0,0 +1,152 @@\n+<?hh // strict\n+/**\n+ * @copyright   2010-2015, The Titon Project\n+ * @license     http://opensource.org/licenses/bsd-license.php\n+ * @link        http://titon.io\n+ */\n+\n+namespace Titon\\Console;\n+\n+use Titon\\Console\\Input;\n+use Titon\\Console\\Output;\n+use Titon\\Console\\InputDefinition\\Flag;\n+\n+/**\n+ * The `Console` class bootstraps and handles Input and Output to process and\n+ * run necessary commands.\n+ *\n+ * @package Titon\\Console\n+ */\n+class Console {\n+\n+    /**\n+     * The `Command` object to run\n+     *\n+     * @var \\Titon\\Console\\Command|null\n+     */\n+    protected ?Command $command;\n+\n+    /**\n+     * The `Input` object used to retrieve parsed parameters and commands.\n+     *\n+     * @var \\Titon\\Console\\Input\n+     */\n+    protected Input $input;\n+\n+    /**\n+     * The `Output` object used to send response data to the user.\n+     *\n+     * @var \\Titon\\Console\\Output\n+     */\n+    protected Output $output;\n+\n+    /**\n+     * Construct a new `Console` application.\n+     */\n+    public function __construct() {\n+        $this->input = Input::getInstance();\n+        $this->output = Output::getInstance();\n+    }\n+\n+    /**\n+     * Add a `Command` to the application to be parsed by the `Input`.\n+     *\n+     * @param Command $command  The `Command` object to add\n+     *\n+     * @return $this\n+     */\n+    public function addCommand(Command $command): this {\n+        $command->setInput($this->input);\n+        $command->configure();\n+\n+        $this->input->addCommand($command);\n+\n+        return $this;\n+    }\n+\n+    /**\n+     * Bootstrap the `Console` application with default parameters and global\n+     * settings.\n+     */\n+    protected function bootstrap(): void {\n+        $this->input->addFlag((new Flag('help', 'Display this help screen.'))\n+            ->alias('h'));\n+        $this->input->addFlag((new Flag('quiet', 'Suppress all output.'))\n+            ->alias('q'));\n+        $this->input->addFlag((new Flag('verbose', 'Set the verbosity of the application\\'s output.'))\n+            ->alias('v')\n+            ->setStackable(true));\n+    }\n+\n+    /**\n+     * Run the `Console` application.\n+     */\n+    public function run(): void {\n+        $this->bootstrap();\n+        $this->command = $this->input->getActiveCommand();\n+        if (is_null($this->command)) {\n+            $this->input->parse();\n+            $this->renderHelpScreen();\n+        } else {\n+            $this->runCommand($this->command);\n+        }\n+    }\n+\n+    /**\n+     * Register and run the `Command` object.\n+     *\n+     * @param Command $command  The `Command` to run\n+     */\n+    public function runCommand(Command $command): void {\n+        $command->registerInput();\n+        $this->input->parse();\n+\n+        if (!is_null($flag = $this->input->getFlag('help'))) {\n+            invariant($flag instanceof Flag, \"Must be a Flag.\");","path":"src/Titon/Console/Console.hh","position":105,"original_position":105,"commit_id":"9e9050b460d89ebe083483b889c790c9ca4f9256","original_commit_id":"9e9050b460d89ebe083483b889c790c9ca4f9256","user":{"login":"exonintrendo","id":3135216,"avatar_url":"https://avatars.githubusercontent.com/u/3135216?v=3","gravatar_id":"","url":"https://api.github.com/users/exonintrendo","html_url":"https://github.com/exonintrendo","followers_url":"https://api.github.com/users/exonintrendo/followers","following_url":"https://api.github.com/users/exonintrendo/following{/other_user}","gists_url":"https://api.github.com/users/exonintrendo/gists{/gist_id}","starred_url":"https://api.github.com/users/exonintrendo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exonintrendo/subscriptions","organizations_url":"https://api.github.com/users/exonintrendo/orgs","repos_url":"https://api.github.com/users/exonintrendo/repos","events_url":"https://api.github.com/users/exonintrendo/events{/privacy}","received_events_url":"https://api.github.com/users/exonintrendo/received_events","type":"User","site_admin":false},"body":"getFlag will return null if the key passed in doesn't exist.","created_at":"2015-03-10T00:48:33Z","updated_at":"2015-03-10T00:48:33Z","html_url":"https://github.com/titon/framework/pull/76#discussion_r26091354","pull_request_url":"https://api.github.com/repos/titon/framework/pulls/76","_links":{"self":{"href":"https://api.github.com/repos/titon/framework/pulls/comments/26091354"},"html":{"href":"https://github.com/titon/framework/pull/76#discussion_r26091354"},"pull_request":{"href":"https://api.github.com/repos/titon/framework/pulls/76"}}},"pull_request":{"url":"https://api.github.com/repos/titon/framework/pulls/76","id":30804695,"html_url":"https://github.com/titon/framework/pull/76","diff_url":"https://github.com/titon/framework/pull/76.diff","patch_url":"https://github.com/titon/framework/pull/76.patch","issue_url":"https://api.github.com/repos/titon/framework/issues/76","number":76,"state":"open","locked":false,"title":"Console package","user":{"login":"exonintrendo","id":3135216,"avatar_url":"https://avatars.githubusercontent.com/u/3135216?v=3","gravatar_id":"","url":"https://api.github.com/users/exonintrendo","html_url":"https://github.com/exonintrendo","followers_url":"https://api.github.com/users/exonintrendo/followers","following_url":"https://api.github.com/users/exonintrendo/following{/other_user}","gists_url":"https://api.github.com/users/exonintrendo/gists{/gist_id}","starred_url":"https://api.github.com/users/exonintrendo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/exonintrendo/subscriptions","organizations_url":"https://api.github.com/users/exonintrendo/orgs","repos_url":"https://api.github.com/users/exonintrendo/repos","events_url":"https://api.github.com/users/exonintrendo/events{/privacy}","received_events_url":"https://api.github.com/users/exonintrendo/received_events","type":"User","site_admin":false},"body":"Console package for building command line applications.","created_at":"2015-03-09T22:03:59Z","updated_at":"2015-03-10T00:48:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd2621915d5569ee73d6eff8274a2f9dfe25d98f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/titon/framework/pulls/76/commits","review_comments_url":"https://api.github.com/repos/titon/framework/pulls/76/comments","review_comment_url":"https://api.github.com/repos/titon/framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/titon/framework/issues/76/comments","statuses_url":"https://api.github.com/repos/titon/framework/statuses/9e9050b460d89ebe083483b889c790c9ca4f9256","head":{"label":"titon:console-package","ref":"console-package","sha":"9e9050b460d89ebe083483b889c790c9ca4f9256","user":{"login":"titon","id":224313,"avatar_url":"https://avatars.githubusercontent.com/u/224313?v=3","gravatar_id":"","url":"https://api.github.com/users/titon","html_url":"https://github.com/titon","followers_url":"https://api.github.com/users/titon/followers","following_url":"https://api.github.com/users/titon/following{/other_user}","gists_url":"https://api.github.com/users/titon/gists{/gist_id}","starred_url":"https://api.github.com/users/titon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titon/subscriptions","organizations_url":"https://api.github.com/users/titon/orgs","repos_url":"https://api.github.com/users/titon/repos","events_url":"https://api.github.com/users/titon/events{/privacy}","received_events_url":"https://api.github.com/users/titon/received_events","type":"Organization","site_admin":false},"repo":{"id":20363624,"name":"framework","full_name":"titon/framework","owner":{"login":"titon","id":224313,"avatar_url":"https://avatars.githubusercontent.com/u/224313?v=3","gravatar_id":"","url":"https://api.github.com/users/titon","html_url":"https://github.com/titon","followers_url":"https://api.github.com/users/titon/followers","following_url":"https://api.github.com/users/titon/following{/other_user}","gists_url":"https://api.github.com/users/titon/gists{/gist_id}","starred_url":"https://api.github.com/users/titon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titon/subscriptions","organizations_url":"https://api.github.com/users/titon/orgs","repos_url":"https://api.github.com/users/titon/repos","events_url":"https://api.github.com/users/titon/events{/privacy}","received_events_url":"https://api.github.com/users/titon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/titon/framework","description":"A modular Hack framework that runs on HHVM.","fork":false,"url":"https://api.github.com/repos/titon/framework","forks_url":"https://api.github.com/repos/titon/framework/forks","keys_url":"https://api.github.com/repos/titon/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/titon/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/titon/framework/teams","hooks_url":"https://api.github.com/repos/titon/framework/hooks","issue_events_url":"https://api.github.com/repos/titon/framework/issues/events{/number}","events_url":"https://api.github.com/repos/titon/framework/events","assignees_url":"https://api.github.com/repos/titon/framework/assignees{/user}","branches_url":"https://api.github.com/repos/titon/framework/branches{/branch}","tags_url":"https://api.github.com/repos/titon/framework/tags","blobs_url":"https://api.github.com/repos/titon/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/titon/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/titon/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/titon/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/titon/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/titon/framework/languages","stargazers_url":"https://api.github.com/repos/titon/framework/stargazers","contributors_url":"https://api.github.com/repos/titon/framework/contributors","subscribers_url":"https://api.github.com/repos/titon/framework/subscribers","subscription_url":"https://api.github.com/repos/titon/framework/subscription","commits_url":"https://api.github.com/repos/titon/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/titon/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/titon/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/titon/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/titon/framework/contents/{+path}","compare_url":"https://api.github.com/repos/titon/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/titon/framework/merges","archive_url":"https://api.github.com/repos/titon/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/titon/framework/downloads","issues_url":"https://api.github.com/repos/titon/framework/issues{/number}","pulls_url":"https://api.github.com/repos/titon/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/titon/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/titon/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/titon/framework/labels{/name}","releases_url":"https://api.github.com/repos/titon/framework/releases{/id}","created_at":"2014-05-31T19:37:47Z","updated_at":"2015-03-08T19:28:28Z","pushed_at":"2015-03-09T22:19:36Z","git_url":"git://github.com/titon/framework.git","ssh_url":"git@github.com:titon/framework.git","clone_url":"https://github.com/titon/framework.git","svn_url":"https://github.com/titon/framework","homepage":"http://titon.io","size":3341,"stargazers_count":114,"watchers_count":114,"language":"Hack","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":114,"default_branch":"master"}},"base":{"label":"titon:master","ref":"master","sha":"082a3ed7e1f79e2595dff5ad36eab982aea772e3","user":{"login":"titon","id":224313,"avatar_url":"https://avatars.githubusercontent.com/u/224313?v=3","gravatar_id":"","url":"https://api.github.com/users/titon","html_url":"https://github.com/titon","followers_url":"https://api.github.com/users/titon/followers","following_url":"https://api.github.com/users/titon/following{/other_user}","gists_url":"https://api.github.com/users/titon/gists{/gist_id}","starred_url":"https://api.github.com/users/titon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titon/subscriptions","organizations_url":"https://api.github.com/users/titon/orgs","repos_url":"https://api.github.com/users/titon/repos","events_url":"https://api.github.com/users/titon/events{/privacy}","received_events_url":"https://api.github.com/users/titon/received_events","type":"Organization","site_admin":false},"repo":{"id":20363624,"name":"framework","full_name":"titon/framework","owner":{"login":"titon","id":224313,"avatar_url":"https://avatars.githubusercontent.com/u/224313?v=3","gravatar_id":"","url":"https://api.github.com/users/titon","html_url":"https://github.com/titon","followers_url":"https://api.github.com/users/titon/followers","following_url":"https://api.github.com/users/titon/following{/other_user}","gists_url":"https://api.github.com/users/titon/gists{/gist_id}","starred_url":"https://api.github.com/users/titon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titon/subscriptions","organizations_url":"https://api.github.com/users/titon/orgs","repos_url":"https://api.github.com/users/titon/repos","events_url":"https://api.github.com/users/titon/events{/privacy}","received_events_url":"https://api.github.com/users/titon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/titon/framework","description":"A modular Hack framework that runs on HHVM.","fork":false,"url":"https://api.github.com/repos/titon/framework","forks_url":"https://api.github.com/repos/titon/framework/forks","keys_url":"https://api.github.com/repos/titon/framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/titon/framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/titon/framework/teams","hooks_url":"https://api.github.com/repos/titon/framework/hooks","issue_events_url":"https://api.github.com/repos/titon/framework/issues/events{/number}","events_url":"https://api.github.com/repos/titon/framework/events","assignees_url":"https://api.github.com/repos/titon/framework/assignees{/user}","branches_url":"https://api.github.com/repos/titon/framework/branches{/branch}","tags_url":"https://api.github.com/repos/titon/framework/tags","blobs_url":"https://api.github.com/repos/titon/framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/titon/framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/titon/framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/titon/framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/titon/framework/statuses/{sha}","languages_url":"https://api.github.com/repos/titon/framework/languages","stargazers_url":"https://api.github.com/repos/titon/framework/stargazers","contributors_url":"https://api.github.com/repos/titon/framework/contributors","subscribers_url":"https://api.github.com/repos/titon/framework/subscribers","subscription_url":"https://api.github.com/repos/titon/framework/subscription","commits_url":"https://api.github.com/repos/titon/framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/titon/framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/titon/framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/titon/framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/titon/framework/contents/{+path}","compare_url":"https://api.github.com/repos/titon/framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/titon/framework/merges","archive_url":"https://api.github.com/repos/titon/framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/titon/framework/downloads","issues_url":"https://api.github.com/repos/titon/framework/issues{/number}","pulls_url":"https://api.github.com/repos/titon/framework/pulls{/number}","milestones_url":"https://api.github.com/repos/titon/framework/milestones{/number}","notifications_url":"https://api.github.com/repos/titon/framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/titon/framework/labels{/name}","releases_url":"https://api.github.com/repos/titon/framework/releases{/id}","created_at":"2014-05-31T19:37:47Z","updated_at":"2015-03-08T19:28:28Z","pushed_at":"2015-03-09T22:19:36Z","git_url":"git://github.com/titon/framework.git","ssh_url":"git@github.com:titon/framework.git","clone_url":"https://github.com/titon/framework.git","svn_url":"https://github.com/titon/framework","homepage":"http://titon.io","size":3341,"stargazers_count":114,"watchers_count":114,"language":"Hack","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/titon/framework/pulls/76"},"html":{"href":"https://github.com/titon/framework/pull/76"},"issue":{"href":"https://api.github.com/repos/titon/framework/issues/76"},"comments":{"href":"https://api.github.com/repos/titon/framework/issues/76/comments"},"review_comments":{"href":"https://api.github.com/repos/titon/framework/pulls/76/comments"},"review_comment":{"href":"https://api.github.com/repos/titon/framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/titon/framework/pulls/76/commits"},"statuses":{"href":"https://api.github.com/repos/titon/framework/statuses/9e9050b460d89ebe083483b889c790c9ca4f9256"}}}}