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