#!/usr/bin/env python3
"""
Usage: list-bad-xrefs modules... filenames...

Prints the bad docstring cross-references in the given modules.

Similar to running C{epydoc -v}, but:
  - The output is organized so that it is easy to identify the code needing
    fixing.
  - If a cross-reference is to an external module, its references are included
    automatically.
"""
# pyflyby/list-bad-xrefs
# Copyright (C) 2011, 2014 Karl Chen.
# License: MIT http://opensource.org/licenses/MIT

from __future__ import absolute_import, division, with_statement
from __future__ import print_function

from   pyflyby._cmdline         import parse_args, syntax
from   pyflyby._docxref         import find_bad_doc_cross_references


def main():
    options, args = parse_args()
    if not args:
        syntax()
    for rec in find_bad_doc_cross_references(args):
        module, linenos, container_name, identifier = rec
        for lineno in linenos or ["?"]:
            print("%s:%s: undefined docstring cross-reference in %s: %s" % (
                module.filename, lineno, container_name, identifier))


if __name__ == '__main__':
    main()
