Adds completion for the --ignore-fields
tag.
This commit is contained in:
parent
860181e278
commit
a8716e6482
@ -6,7 +6,8 @@ from .. import repo
|
||||
from ..uis import get_ui
|
||||
from .. import endecoder
|
||||
from ..utils import resolve_citekey_list
|
||||
from ..completion import CiteKeyCompletion
|
||||
from ..endecoder import BIBFIELD_ORDER
|
||||
from ..completion import CiteKeyCompletion, CommaSeparatedListCompletion
|
||||
|
||||
|
||||
class CommaSeparatedList(argparse.Action):
|
||||
@ -15,11 +16,17 @@ class CommaSeparatedList(argparse.Action):
|
||||
setattr(namespace, self.dest, [s for s in values.split(',') if s])
|
||||
|
||||
|
||||
class FieldCommaSeparatedListCompletion(CommaSeparatedListCompletion):
|
||||
|
||||
values = BIBFIELD_ORDER
|
||||
|
||||
|
||||
def parser(subparsers, conf):
|
||||
parser = subparsers.add_parser('export', help='export bibliography')
|
||||
parser.add_argument(
|
||||
'--ignore-fields', default=[], action=CommaSeparatedList,
|
||||
help='exclude field(s) from output (comma separated if multiple)')
|
||||
help='exclude field(s) from output (comma separated if multiple)'
|
||||
).completer = FieldCommaSeparatedListCompletion(conf)
|
||||
# parser.add_argument('-f', '--bib-format', default='bibtex',
|
||||
# help='export format')
|
||||
parser.add_argument('citekeys', nargs='*', help='one or several citekeys'
|
||||
|
@ -57,3 +57,15 @@ class TagModifierCompletion(BaseCompleter):
|
||||
partial_expr = prefix[:start]
|
||||
t_prefix = prefix[start:]
|
||||
return [partial_expr + t for t in tags if t.startswith(t_prefix)]
|
||||
|
||||
|
||||
class CommaSeparatedListCompletion(BaseCompleter):
|
||||
|
||||
values = []
|
||||
|
||||
def _complete(self, prefix, **kwargs):
|
||||
split = prefix.split(',')
|
||||
item_prefix = split[-1]
|
||||
partial = split[:-1]
|
||||
return [','.join(partial + [x]) for x in self.values
|
||||
if x.startswith(item_prefix)]
|
||||
|
@ -27,6 +27,11 @@ else:
|
||||
BP_ENTRYTYPE_KEY = 'type'
|
||||
|
||||
|
||||
BIBFIELD_ORDER = ['author', 'title', 'journal', 'institution', 'publisher',
|
||||
'year', 'month', 'number', 'volume', 'pages', 'link', 'doi',
|
||||
'note', 'abstract']
|
||||
|
||||
|
||||
def sanitize_citekey(record):
|
||||
record[BP_ID_KEY] = record[BP_ID_KEY].strip('\n')
|
||||
return record
|
||||
@ -54,11 +59,6 @@ def customizations(record):
|
||||
return record
|
||||
|
||||
|
||||
bibfield_order = ['author', 'title', 'journal', 'institution', 'publisher',
|
||||
'year', 'month', 'number', 'volume', 'pages', 'link', 'doi',
|
||||
'note', 'abstract']
|
||||
|
||||
|
||||
class EnDecoder(object):
|
||||
""" Encode and decode content.
|
||||
|
||||
@ -71,7 +71,7 @@ class EnDecoder(object):
|
||||
"""
|
||||
|
||||
bwriter = bp.bwriter.BibTexWriter()
|
||||
bwriter.display_order = bibfield_order
|
||||
bwriter.display_order = BIBFIELD_ORDER
|
||||
|
||||
def encode_metadata(self, metadata):
|
||||
return yaml.safe_dump(metadata, allow_unicode=True,
|
||||
|
Loading…
x
Reference in New Issue
Block a user