You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

#!/usr/bin/env python2
# -*- coding:utf-8 -*-
import argparse
import collections
from papers.ui import UI
from papers import configs
from papers import commands
cmds = collections.OrderedDict([
('init', commands.init_cmd),
('add', commands.add_cmd),
('add_library', commands.add_library_cmd),
('import', commands.import_cmd),
('export', commands.export_cmd),
('list', commands.list_cmd),
('edit', commands.edit_cmd),
('remove', commands.remove_cmd),
('open', commands.open_cmd),
('websearch', commands.websearch_cmd),
('tags', commands.tags_cmd),
('attach', commands.attach_cmd),
])
config = configs.read_config()
ui = UI(config)
# Extend with plugin commands
plugs = configs.get_plugins(config)
for plugname in plugs:
module_name = 'papers.plugins.' + plugname + '.' + plugname + '_cmd'
plug = __import__(module_name, globals(), locals(),
['parser', 'command'], -1)
cmds.update(collections.OrderedDict([(plugname, plug)]))
parser = argparse.ArgumentParser(description="research papers repository")
subparsers = parser.add_subparsers(title="valid commands", dest="command")
for cmd_mod in cmds.values():
subparser = cmd_mod.parser(subparsers, config)
args = parser.parse_args()
args.config = config
args.ui = ui
cmd = args.command
del args.command
cmds[cmd].command(**vars(args))