diff options
author | Jason Ribeiro <jason AT jribDOTnet> | 2018-05-14 16:52:26 -0400 |
---|---|---|
committer | Jason Ribeiro <jason AT jribDOTnet> | 2018-05-14 16:54:52 -0400 |
commit | 9014d965265fe487821724d5098bf84a22251336 (patch) | |
tree | c80ad32e83669f1fd6a58e5882a3591180acdb78 /pgcli | |
parent | 7d0f866afb714abc3510417f641e5e1384e202dc (diff) |
Add completion for table formats
Diffstat (limited to 'pgcli')
-rw-r--r-- | pgcli/packages/sqlcompletion.py | 4 | ||||
-rw-r--r-- | pgcli/pgcompleter.py | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/pgcli/packages/sqlcompletion.py b/pgcli/packages/sqlcompletion.py index f92a8a71..aa829853 100644 --- a/pgcli/packages/sqlcompletion.py +++ b/pgcli/packages/sqlcompletion.py @@ -28,6 +28,7 @@ Schema.__new__.__defaults__ = (False,) # used to ensure that the alias we suggest is unique FromClauseItem = namedtuple('FromClauseItem', 'schema table_refs local_tables') Table = namedtuple('Table', ['schema', 'table_refs', 'local_tables']) +TableFormat = namedtuple('TableFormat', []) View = namedtuple('View', ['schema', 'table_refs']) # JoinConditions are suggested after ON, e.g. 'foo.barid = bar.barid' JoinCondition = namedtuple('JoinCondition', ['table_refs', 'parent']) @@ -252,6 +253,9 @@ def suggest_special(text): if cmd in ('\\c', '\\connect'): return (Database(),) + if cmd == '\\T': + return (TableFormat(),) + if cmd == '\\dn': return (Schema(),) diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py index cba9fb7c..72d54d82 100644 --- a/pgcli/pgcompleter.py +++ b/pgcli/pgcompleter.py @@ -4,13 +4,15 @@ import re from itertools import count, repeat, chain import operator from collections import namedtuple, defaultdict, OrderedDict +from cli_helpers.tabular_output import TabularOutputFormatter from pgspecial.namedqueries import NamedQueries from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.contrib.completers import PathCompleter from prompt_toolkit.document import Document -from .packages.sqlcompletion import (FromClauseItem, - suggest_type, Special, Database, Schema, Table, Function, Column, View, - Keyword, NamedQuery, Datatype, Alias, Path, JoinCondition, Join) +from .packages.sqlcompletion import ( + FromClauseItem, suggest_type, Special, Database, Schema, Table, + TableFormat, Function, Column, View, Keyword, NamedQuery, + Datatype, Alias, Path, JoinCondition, Join) from .packages.parseutils.meta import ColumnMetadata, ForeignKey from .packages.parseutils.utils import last_word from .packages.parseutils.tables import TableReference @@ -321,7 +323,8 @@ class PGCompleter(Completer): return [] prio_order = [ 'keyword', 'function', 'view', 'table', 'datatype', 'database', - 'schema', 'column', 'table alias', 'join', 'name join', 'fk join' + 'schema', 'column', 'table alias', 'join', 'name join', 'fk join', + 'table format' ] type_priority = prio_order.index(meta) if meta in prio_order else -1 text = last_word(text, include='most_punctuations').lower() @@ -778,6 +781,9 @@ class PGCompleter(Completer): tables = [self._make_cand(t, alias, suggestion) for t in tables] return self.find_matches(word_before_cursor, tables, meta='table') + def get_table_formats(self, _, word_before_cursor): + formats = TabularOutputFormatter().supported_formats + return self.find_matches(word_before_cursor, formats, meta='table format') def get_view_matches(self, suggestion, word_before_cursor, alias=False): views = self.populate_schema_objects(suggestion.schema, 'views') @@ -861,6 +867,7 @@ class PGCompleter(Completer): Function: get_function_matches, Schema: get_schema_matches, Table: get_table_matches, + TableFormat: get_table_formats, View: get_view_matches, Alias: get_alias_matches, Database: get_database_matches, |