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.
53 lines
1.5 KiB
53 lines
1.5 KiB
#!/usr/bin/env python2
|
|
# -*- coding:utf-8 -*-
|
|
import sys
|
|
|
|
import argparse
|
|
import collections
|
|
|
|
from .ui import UI
|
|
from . import configs
|
|
from . import commands
|
|
from . import plugin
|
|
|
|
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),
|
|
('tag', commands.tag_cmd),
|
|
('attach', commands.attach_cmd),
|
|
('update', commands.update_cmd),
|
|
])
|
|
|
|
|
|
def execute(raw_args = sys.argv):
|
|
config = configs.read_config()
|
|
ui = UI(config)
|
|
|
|
# Extend with plugin commands
|
|
plugin.load_plugins(config, ui, configs.get_plugins(config))
|
|
for p in plugin.get_plugins().values():
|
|
cmds.update(collections.OrderedDict([(p.name, p)]))
|
|
|
|
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) # why do we return the subparser ?
|
|
|
|
args = parser.parse_args(raw_args[1:])
|
|
args.config = config
|
|
|
|
args.ui = ui
|
|
cmd = args.command
|
|
del args.command
|
|
|
|
cmds[cmd].command(**vars(args))
|