#!python
"""
Construct, modify or query a tree data structure for fast subtree queries.

Usage:
  fastsubtrees <command> [<args>...]

Available commands:
  tree         Create or modify a tree.
  attribute    Create, modify or remove an attribute.
  query        List node IDs and/or attributes in a subtree.

See 'fastsubtrees <command> --help' for more information on a specific command.

"""
from docopt import docopt
from fastsubtrees import __version__, error, logger
from fastsubtrees.commands import _support

if __name__ == '__main__':
  args = docopt(__doc__, version=__version__, options_first=True)
  command = args['<command>']
  if command == 'tree':
    import fastsubtrees.commands.tree as cmd
  elif command == 'query':
    import fastsubtrees.commands.query as cmd
  elif command == 'attribute':
    import fastsubtrees.commands.attribute as cmd
  else:
    exit(f"'{command}' is not a fastsubtrees command.\n"+\
        "See fastsubtrees --help.")
  argv = [command] + args["<args>"]
  cmd_args = docopt(cmd.__doc__, version=__version__, argv=argv)
  _support.setup_verbosity(cmd_args)
  try:
    cmd.main(cmd_args)
  except (error.FastsubtreesError, FileNotFoundError) as e:
    logger.error(e)
    exit(1)
