|
|
|
@ -32,56 +32,56 @@ CORE_CMDS = collections.OrderedDict([
|
|
|
|
|
|
|
|
|
|
def execute(raw_args=sys.argv):
|
|
|
|
|
|
|
|
|
|
conf_parser = argparse.ArgumentParser(prog="pubs", add_help=False)
|
|
|
|
|
conf_parser.add_argument("-c", "--config", help="path to config file",
|
|
|
|
|
type=str, metavar="FILE")
|
|
|
|
|
conf_parser.add_argument('--force-colors', dest='force_colors',
|
|
|
|
|
action='store_true', default=False,
|
|
|
|
|
help='color are not disabled when piping to a file or other commands')
|
|
|
|
|
#conf_parser.add_argument("-u", "--update", help="update config if needed",
|
|
|
|
|
# default=False, action='store_true')
|
|
|
|
|
top_args, remaining_args = conf_parser.parse_known_args(raw_args[1:])
|
|
|
|
|
|
|
|
|
|
if top_args.config:
|
|
|
|
|
conf_path = top_args.config
|
|
|
|
|
else:
|
|
|
|
|
conf_path = config.get_confpath(verify=False) # will be checked on load
|
|
|
|
|
|
|
|
|
|
# Loading config
|
|
|
|
|
if len(remaining_args) > 0 and remaining_args[0] != 'init':
|
|
|
|
|
try:
|
|
|
|
|
try:
|
|
|
|
|
conf_parser = argparse.ArgumentParser(prog="pubs", add_help=False)
|
|
|
|
|
conf_parser.add_argument("-c", "--config", help="path to config file",
|
|
|
|
|
type=str, metavar="FILE")
|
|
|
|
|
conf_parser.add_argument('--force-colors', dest='force_colors',
|
|
|
|
|
action='store_true', default=False,
|
|
|
|
|
help='color are not disabled when piping to a file or other commands')
|
|
|
|
|
#conf_parser.add_argument("-u", "--update", help="update config if needed",
|
|
|
|
|
# default=False, action='store_true')
|
|
|
|
|
top_args, remaining_args = conf_parser.parse_known_args(raw_args[1:])
|
|
|
|
|
|
|
|
|
|
if top_args.config:
|
|
|
|
|
conf_path = top_args.config
|
|
|
|
|
else:
|
|
|
|
|
conf_path = config.get_confpath(verify=False) # will be checked on load
|
|
|
|
|
|
|
|
|
|
# Loading config
|
|
|
|
|
if len(remaining_args) > 0 and remaining_args[0] != 'init':
|
|
|
|
|
conf = config.load_conf(path=conf_path, check=False)
|
|
|
|
|
if update.update_check(conf, path=conf.filename):
|
|
|
|
|
# an update happened, reload conf.
|
|
|
|
|
conf = config.load_conf(path=conf_path, check=False)
|
|
|
|
|
config.check_conf(conf)
|
|
|
|
|
except IOError as e:
|
|
|
|
|
print('error: {}'.format(str(e)))
|
|
|
|
|
sys.exit()
|
|
|
|
|
else:
|
|
|
|
|
conf = config.load_default_conf()
|
|
|
|
|
conf.filename = conf_path
|
|
|
|
|
|
|
|
|
|
uis.init_ui(conf, force_colors=top_args.force_colors)
|
|
|
|
|
ui = uis.get_ui()
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="research papers repository",
|
|
|
|
|
prog="pubs", add_help=True)
|
|
|
|
|
parser.add_argument('--version', action='version', version=__version__)
|
|
|
|
|
subparsers = parser.add_subparsers(title="valid commands", dest="command")
|
|
|
|
|
subparsers.required = True
|
|
|
|
|
|
|
|
|
|
# Populate the parser with core commands
|
|
|
|
|
for cmd_name, cmd_mod in CORE_CMDS.items():
|
|
|
|
|
cmd_parser = cmd_mod.parser(subparsers)
|
|
|
|
|
cmd_parser.set_defaults(func=cmd_mod.command)
|
|
|
|
|
|
|
|
|
|
# Extend with plugin commands
|
|
|
|
|
plugins.load_plugins(conf, ui)
|
|
|
|
|
for p in plugins.get_plugins().values():
|
|
|
|
|
p.update_parser(subparsers)
|
|
|
|
|
|
|
|
|
|
# Parse and run appropriate command
|
|
|
|
|
args = parser.parse_args(remaining_args)
|
|
|
|
|
args.prog = "pubs" # FIXME?
|
|
|
|
|
args.func(conf, args)
|
|
|
|
|
else:
|
|
|
|
|
conf = config.load_default_conf()
|
|
|
|
|
conf.filename = conf_path
|
|
|
|
|
|
|
|
|
|
uis.init_ui(conf, force_colors=top_args.force_colors)
|
|
|
|
|
ui = uis.get_ui()
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="research papers repository",
|
|
|
|
|
prog="pubs", add_help=True)
|
|
|
|
|
parser.add_argument('--version', action='version', version=__version__)
|
|
|
|
|
subparsers = parser.add_subparsers(title="valid commands", dest="command")
|
|
|
|
|
subparsers.required = True
|
|
|
|
|
|
|
|
|
|
# Populate the parser with core commands
|
|
|
|
|
for cmd_name, cmd_mod in CORE_CMDS.items():
|
|
|
|
|
cmd_parser = cmd_mod.parser(subparsers)
|
|
|
|
|
cmd_parser.set_defaults(func=cmd_mod.command)
|
|
|
|
|
|
|
|
|
|
# Extend with plugin commands
|
|
|
|
|
plugins.load_plugins(conf, ui)
|
|
|
|
|
for p in plugins.get_plugins().values():
|
|
|
|
|
p.update_parser(subparsers)
|
|
|
|
|
|
|
|
|
|
# Parse and run appropriate command
|
|
|
|
|
args = parser.parse_args(remaining_args)
|
|
|
|
|
args.prog = "pubs" # FIXME?
|
|
|
|
|
args.func(conf, args)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
uis.get_ui().handle_exception(e)
|
|
|
|
|