{"action":"created","comment":{"url":"https://api.github.com/repos/dbcli/pgcli/pulls/comments/33608413","id":33608413,"diff_hunk":"@@ -18,6 +18,32 @@\n class CommandNotFound(Exception):\n     pass\n \n+\n+@export\n+class PGSpecial(object):\n+    def __init__(self):\n+        self.timing_enabled = True\n+\n+        self.commands = COMMANDS.copy()\n+        self.register(self.show_help, '\\\\?', '\\\\?', 'Show Help.',\n+                      arg_type=NO_QUERY)\n+\n+    def register(self, *args, **kwargs):\n+        register_special_command(*args, command_dict=self.commands, **kwargs)\n+\n+    def execute(self, cur, sql):\n+        return execute(cur, sql, self.commands)","path":"pgcli/packages/pgspecial/main.py","position":18,"original_position":18,"commit_id":"581061440b89971432009a43e2d7a0abe321d77c","original_commit_id":"581061440b89971432009a43e2d7a0abe321d77c","user":{"login":"darikg","id":6875882,"avatar_url":"https://avatars.githubusercontent.com/u/6875882?v=3","gravatar_id":"","url":"https://api.github.com/users/darikg","html_url":"https://github.com/darikg","followers_url":"https://api.github.com/users/darikg/followers","following_url":"https://api.github.com/users/darikg/following{/other_user}","gists_url":"https://api.github.com/users/darikg/gists{/gist_id}","starred_url":"https://api.github.com/users/darikg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darikg/subscriptions","organizations_url":"https://api.github.com/users/darikg/orgs","repos_url":"https://api.github.com/users/darikg/repos","events_url":"https://api.github.com/users/darikg/events{/privacy}","received_events_url":"https://api.github.com/users/darikg/received_events","type":"User","site_admin":false},"body":"There's a weird divide in the special commands, where half of them are just shortcuts for longer queries. It makes sense to me, for pgspecial as a standalone package, to be able to run those commands without having to instantiate an an object. It's not important for pgcli though.","created_at":"2015-06-30T18:43:09Z","updated_at":"2015-06-30T18:43:09Z","html_url":"https://github.com/dbcli/pgcli/pull/273#discussion_r33608413","pull_request_url":"https://api.github.com/repos/dbcli/pgcli/pulls/273","_links":{"self":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/comments/33608413"},"html":{"href":"https://github.com/dbcli/pgcli/pull/273#discussion_r33608413"},"pull_request":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/273"}}},"pull_request":{"url":"https://api.github.com/repos/dbcli/pgcli/pulls/273","id":38900243,"html_url":"https://github.com/dbcli/pgcli/pull/273","diff_url":"https://github.com/dbcli/pgcli/pull/273.diff","patch_url":"https://github.com/dbcli/pgcli/pull/273.patch","issue_url":"https://api.github.com/repos/dbcli/pgcli/issues/273","number":273,"state":"open","locked":false,"title":"More specials refactoring","user":{"login":"darikg","id":6875882,"avatar_url":"https://avatars.githubusercontent.com/u/6875882?v=3","gravatar_id":"","url":"https://api.github.com/users/darikg","html_url":"https://github.com/darikg","followers_url":"https://api.github.com/users/darikg/followers","following_url":"https://api.github.com/users/darikg/following{/other_user}","gists_url":"https://api.github.com/users/darikg/gists{/gist_id}","starred_url":"https://api.github.com/users/darikg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darikg/subscriptions","organizations_url":"https://api.github.com/users/darikg/orgs","repos_url":"https://api.github.com/users/darikg/repos","events_url":"https://api.github.com/users/darikg/events{/privacy}","received_events_url":"https://api.github.com/users/darikg/received_events","type":"User","site_admin":false},"body":"Building on @amjith's last specials refactor, this wraps up a lot of the specials.main file into a PGSpecial class, which makes it possible for multiple PGCli instances to coexist in the same python interpreter without interfering with each other through module level globals in pgspecial. While doing this I was also able to weaken some of the coupling between pgspecial, pgexecute, and pgcli.\r\n\r\nAs before, special commands that do not manipulate state are defined by the `@special_command` decorator, which stores metadata in the `COMMANDS` variable. During initialization of a new PGSpecial object, a *copy* of `COMMANDS` is stored in the member variable `commands`. Further special method registration is done through the method PGSpecial.register, which of course modifies only the member variable, not the module one.\r\n\r\nOne hesitation I had was where the code for `\\x` and `\\timing` belonged. Because they're ultimately responsible for mutating the state of the cli application I moved them out of the specials package and into PGCli, in parallel to `\\c` and `\\#`.","created_at":"2015-06-30T16:56:17Z","updated_at":"2015-06-30T18:43:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14337d5a1c2aaea7db76a99fa336659256902674","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dbcli/pgcli/pulls/273/commits","review_comments_url":"https://api.github.com/repos/dbcli/pgcli/pulls/273/comments","review_comment_url":"https://api.github.com/repos/dbcli/pgcli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dbcli/pgcli/issues/273/comments","statuses_url":"https://api.github.com/repos/dbcli/pgcli/statuses/581061440b89971432009a43e2d7a0abe321d77c","head":{"label":"dbcli:darikg/specials-refactor-more","ref":"darikg/specials-refactor-more","sha":"581061440b89971432009a43e2d7a0abe321d77c","user":{"login":"dbcli","id":11810727,"avatar_url":"https://avatars.githubusercontent.com/u/11810727?v=3","gravatar_id":"","url":"https://api.github.com/users/dbcli","html_url":"https://github.com/dbcli","followers_url":"https://api.github.com/users/dbcli/followers","following_url":"https://api.github.com/users/dbcli/following{/other_user}","gists_url":"https://api.github.com/users/dbcli/gists{/gist_id}","starred_url":"https://api.github.com/users/dbcli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbcli/subscriptions","organizations_url":"https://api.github.com/users/dbcli/orgs","repos_url":"https://api.github.com/users/dbcli/repos","events_url":"https://api.github.com/users/dbcli/events{/privacy}","received_events_url":"https://api.github.com/users/dbcli/received_events","type":"Organization","site_admin":false},"repo":{"id":25126616,"name":"pgcli","full_name":"dbcli/pgcli","owner":{"login":"dbcli","id":11810727,"avatar_url":"https://avatars.githubusercontent.com/u/11810727?v=3","gravatar_id":"","url":"https://api.github.com/users/dbcli","html_url":"https://github.com/dbcli","followers_url":"https://api.github.com/users/dbcli/followers","following_url":"https://api.github.com/users/dbcli/following{/other_user}","gists_url":"https://api.github.com/users/dbcli/gists{/gist_id}","starred_url":"https://api.github.com/users/dbcli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbcli/subscriptions","organizations_url":"https://api.github.com/users/dbcli/orgs","repos_url":"https://api.github.com/users/dbcli/repos","events_url":"https://api.github.com/users/dbcli/events{/privacy}","received_events_url":"https://api.github.com/users/dbcli/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dbcli/pgcli","description":"Postgres CLI with autocompletion and syntax highlighting","fork":false,"url":"https://api.github.com/repos/dbcli/pgcli","forks_url":"https://api.github.com/repos/dbcli/pgcli/forks","keys_url":"https://api.github.com/repos/dbcli/pgcli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbcli/pgcli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbcli/pgcli/teams","hooks_url":"https://api.github.com/repos/dbcli/pgcli/hooks","issue_events_url":"https://api.github.com/repos/dbcli/pgcli/issues/events{/number}","events_url":"https://api.github.com/repos/dbcli/pgcli/events","assignees_url":"https://api.github.com/repos/dbcli/pgcli/assignees{/user}","branches_url":"https://api.github.com/repos/dbcli/pgcli/branches{/branch}","tags_url":"https://api.github.com/repos/dbcli/pgcli/tags","blobs_url":"https://api.github.com/repos/dbcli/pgcli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbcli/pgcli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbcli/pgcli/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbcli/pgcli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbcli/pgcli/statuses/{sha}","languages_url":"https://api.github.com/repos/dbcli/pgcli/languages","stargazers_url":"https://api.github.com/repos/dbcli/pgcli/stargazers","contributors_url":"https://api.github.com/repos/dbcli/pgcli/contributors","subscribers_url":"https://api.github.com/repos/dbcli/pgcli/subscribers","subscription_url":"https://api.github.com/repos/dbcli/pgcli/subscription","commits_url":"https://api.github.com/repos/dbcli/pgcli/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbcli/pgcli/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbcli/pgcli/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbcli/pgcli/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbcli/pgcli/contents/{+path}","compare_url":"https://api.github.com/repos/dbcli/pgcli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbcli/pgcli/merges","archive_url":"https://api.github.com/repos/dbcli/pgcli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbcli/pgcli/downloads","issues_url":"https://api.github.com/repos/dbcli/pgcli/issues{/number}","pulls_url":"https://api.github.com/repos/dbcli/pgcli/pulls{/number}","milestones_url":"https://api.github.com/repos/dbcli/pgcli/milestones{/number}","notifications_url":"https://api.github.com/repos/dbcli/pgcli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbcli/pgcli/labels{/name}","releases_url":"https://api.github.com/repos/dbcli/pgcli/releases{/id}","created_at":"2014-10-12T17:32:33Z","updated_at":"2015-06-30T16:26:47Z","pushed_at":"2015-06-30T16:56:18Z","git_url":"git://github.com/dbcli/pgcli.git","ssh_url":"git@github.com:dbcli/pgcli.git","clone_url":"https://github.com/dbcli/pgcli.git","svn_url":"https://github.com/dbcli/pgcli","homepage":null,"size":2992,"stargazers_count":1918,"watchers_count":1918,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":79,"mirror_url":null,"open_issues_count":37,"forks":79,"open_issues":37,"watchers":1918,"default_branch":"master"}},"base":{"label":"dbcli:master","ref":"master","sha":"adf9a455f65c92d4e7651dcd52a2a074ffdfaaf4","user":{"login":"dbcli","id":11810727,"avatar_url":"https://avatars.githubusercontent.com/u/11810727?v=3","gravatar_id":"","url":"https://api.github.com/users/dbcli","html_url":"https://github.com/dbcli","followers_url":"https://api.github.com/users/dbcli/followers","following_url":"https://api.github.com/users/dbcli/following{/other_user}","gists_url":"https://api.github.com/users/dbcli/gists{/gist_id}","starred_url":"https://api.github.com/users/dbcli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbcli/subscriptions","organizations_url":"https://api.github.com/users/dbcli/orgs","repos_url":"https://api.github.com/users/dbcli/repos","events_url":"https://api.github.com/users/dbcli/events{/privacy}","received_events_url":"https://api.github.com/users/dbcli/received_events","type":"Organization","site_admin":false},"repo":{"id":25126616,"name":"pgcli","full_name":"dbcli/pgcli","owner":{"login":"dbcli","id":11810727,"avatar_url":"https://avatars.githubusercontent.com/u/11810727?v=3","gravatar_id":"","url":"https://api.github.com/users/dbcli","html_url":"https://github.com/dbcli","followers_url":"https://api.github.com/users/dbcli/followers","following_url":"https://api.github.com/users/dbcli/following{/other_user}","gists_url":"https://api.github.com/users/dbcli/gists{/gist_id}","starred_url":"https://api.github.com/users/dbcli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbcli/subscriptions","organizations_url":"https://api.github.com/users/dbcli/orgs","repos_url":"https://api.github.com/users/dbcli/repos","events_url":"https://api.github.com/users/dbcli/events{/privacy}","received_events_url":"https://api.github.com/users/dbcli/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dbcli/pgcli","description":"Postgres CLI with autocompletion and syntax highlighting","fork":false,"url":"https://api.github.com/repos/dbcli/pgcli","forks_url":"https://api.github.com/repos/dbcli/pgcli/forks","keys_url":"https://api.github.com/repos/dbcli/pgcli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbcli/pgcli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbcli/pgcli/teams","hooks_url":"https://api.github.com/repos/dbcli/pgcli/hooks","issue_events_url":"https://api.github.com/repos/dbcli/pgcli/issues/events{/number}","events_url":"https://api.github.com/repos/dbcli/pgcli/events","assignees_url":"https://api.github.com/repos/dbcli/pgcli/assignees{/user}","branches_url":"https://api.github.com/repos/dbcli/pgcli/branches{/branch}","tags_url":"https://api.github.com/repos/dbcli/pgcli/tags","blobs_url":"https://api.github.com/repos/dbcli/pgcli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbcli/pgcli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbcli/pgcli/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbcli/pgcli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbcli/pgcli/statuses/{sha}","languages_url":"https://api.github.com/repos/dbcli/pgcli/languages","stargazers_url":"https://api.github.com/repos/dbcli/pgcli/stargazers","contributors_url":"https://api.github.com/repos/dbcli/pgcli/contributors","subscribers_url":"https://api.github.com/repos/dbcli/pgcli/subscribers","subscription_url":"https://api.github.com/repos/dbcli/pgcli/subscription","commits_url":"https://api.github.com/repos/dbcli/pgcli/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbcli/pgcli/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbcli/pgcli/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbcli/pgcli/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbcli/pgcli/contents/{+path}","compare_url":"https://api.github.com/repos/dbcli/pgcli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbcli/pgcli/merges","archive_url":"https://api.github.com/repos/dbcli/pgcli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbcli/pgcli/downloads","issues_url":"https://api.github.com/repos/dbcli/pgcli/issues{/number}","pulls_url":"https://api.github.com/repos/dbcli/pgcli/pulls{/number}","milestones_url":"https://api.github.com/repos/dbcli/pgcli/milestones{/number}","notifications_url":"https://api.github.com/repos/dbcli/pgcli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbcli/pgcli/labels{/name}","releases_url":"https://api.github.com/repos/dbcli/pgcli/releases{/id}","created_at":"2014-10-12T17:32:33Z","updated_at":"2015-06-30T16:26:47Z","pushed_at":"2015-06-30T16:56:18Z","git_url":"git://github.com/dbcli/pgcli.git","ssh_url":"git@github.com:dbcli/pgcli.git","clone_url":"https://github.com/dbcli/pgcli.git","svn_url":"https://github.com/dbcli/pgcli","homepage":null,"size":2992,"stargazers_count":1918,"watchers_count":1918,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":79,"mirror_url":null,"open_issues_count":37,"forks":79,"open_issues":37,"watchers":1918,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/273"},"html":{"href":"https://github.com/dbcli/pgcli/pull/273"},"issue":{"href":"https://api.github.com/repos/dbcli/pgcli/issues/273"},"comments":{"href":"https://api.github.com/repos/dbcli/pgcli/issues/273/comments"},"review_comments":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/273/comments"},"review_comment":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dbcli/pgcli/pulls/273/commits"},"statuses":{"href":"https://api.github.com/repos/dbcli/pgcli/statuses/581061440b89971432009a43e2d7a0abe321d77c"}}}}