import ast

import click

from parsing.parser import FileVisitor


@click.command()
@click.argument('code', type=click.File('rb'))
@click.option('--printed', default=False, is_flag=True, help='Pretty prints the call tree for each class in the file')
@click.option('--remove-builtins', default=False, is_flag=True, help='Removes builtin functions from call trees')
def cli(code, printed, remove_builtins):
    """
    Parses a file.
    codegrapher [file_name]
    """
    parsed_code = ast.parse(code.read(), filename='code.py')
    visitor = FileVisitor()
    visitor.visit(parsed_code)
    if printed:
        click.echo('Classes in file:')
        for class_object in visitor.classes:
            if remove_builtins:
                class_object.remove_builtins()
            click.echo('=' * 80)
            click.echo(class_object.name)
            click.echo(class_object.pprint())
            click.echo('')

import ast

import click

from graphing.graph import FunctionGrapher
from parsing.parser import FileVisitor


@click.command()
@click.argument('code', type=click.File('rb'))
@click.option('--printed', default=False, is_flag=True, help='Pretty prints the call tree for each class in the file')
@click.option('--remove-builtins', default=False, is_flag=True, help='Removes builtin functions from call trees')
@click.option('--output', help='Graphviz output file name')
def cli(code, printed, remove_builtins, output):
    """
    Parses a file.
    codegrapher [file_name]
    """
    parsed_code = ast.parse(code.read(), filename='code.py')
    visitor = FileVisitor()
    visitor.visit(parsed_code)
    if printed:
        click.echo('Classes in file:')
        for class_object in visitor.classes:
            if remove_builtins:
                class_object.remove_builtins()
            click.echo('=' * 80)
            click.echo(class_object.name)
            click.echo(class_object.pprint())
            click.echo('')
    if output:
        graph = FunctionGrapher()
        class_names = set(cls.name for cls in visitor.classes)
        for cls in visitor.classes:
            graph.add_dict_to_graph(class_names, cls.call_tree)
        graph.add_classes_to_graph(visitor.classes)
        graph.name = output
        graph.render()

Add graphviz file output argument
Add graphviz file output argument

  import ast
  
  import click
  
+ from graphing.graph import FunctionGrapher
  from parsing.parser import FileVisitor
  
  
  @click.command()
  @click.argument('code', type=click.File('rb'))
  @click.option('--printed', default=False, is_flag=True, help='Pretty prints the call tree for each class in the file')
  @click.option('--remove-builtins', default=False, is_flag=True, help='Removes builtin functions from call trees')
+ @click.option('--output', help='Graphviz output file name')
- def cli(code, printed, remove_builtins):
+ def cli(code, printed, remove_builtins, output):
      """
      Parses a file.
      codegrapher [file_name]
      """
      parsed_code = ast.parse(code.read(), filename='code.py')
      visitor = FileVisitor()
      visitor.visit(parsed_code)
      if printed:
          click.echo('Classes in file:')
          for class_object in visitor.classes:
              if remove_builtins:
                  class_object.remove_builtins()
              click.echo('=' * 80)
              click.echo(class_object.name)
              click.echo(class_object.pprint())
              click.echo('')
+     if output:
+         graph = FunctionGrapher()
+         class_names = set(cls.name for cls in visitor.classes)
+         for cls in visitor.classes:
+             graph.add_dict_to_graph(class_names, cls.call_tree)
+         graph.add_classes_to_graph(visitor.classes)
+         graph.name = output
+         graph.render()
  
Add graphviz file output argument
## Code Before:
import ast

import click

from parsing.parser import FileVisitor


@click.command()
@click.argument('code', type=click.File('rb'))
@click.option('--printed', default=False, is_flag=True, help='Pretty prints the call tree for each class in the file')
@click.option('--remove-builtins', default=False, is_flag=True, help='Removes builtin functions from call trees')
def cli(code, printed, remove_builtins):
    """
    Parses a file.
    codegrapher [file_name]
    """
    parsed_code = ast.parse(code.read(), filename='code.py')
    visitor = FileVisitor()
    visitor.visit(parsed_code)
    if printed:
        click.echo('Classes in file:')
        for class_object in visitor.classes:
            if remove_builtins:
                class_object.remove_builtins()
            click.echo('=' * 80)
            click.echo(class_object.name)
            click.echo(class_object.pprint())
            click.echo('')

## Instruction:
Add graphviz file output argument
## Code After:
import ast

import click

from graphing.graph import FunctionGrapher
from parsing.parser import FileVisitor


@click.command()
@click.argument('code', type=click.File('rb'))
@click.option('--printed', default=False, is_flag=True, help='Pretty prints the call tree for each class in the file')
@click.option('--remove-builtins', default=False, is_flag=True, help='Removes builtin functions from call trees')
@click.option('--output', help='Graphviz output file name')
def cli(code, printed, remove_builtins, output):
    """
    Parses a file.
    codegrapher [file_name]
    """
    parsed_code = ast.parse(code.read(), filename='code.py')
    visitor = FileVisitor()
    visitor.visit(parsed_code)
    if printed:
        click.echo('Classes in file:')
        for class_object in visitor.classes:
            if remove_builtins:
                class_object.remove_builtins()
            click.echo('=' * 80)
            click.echo(class_object.name)
            click.echo(class_object.pprint())
            click.echo('')
    if output:
        graph = FunctionGrapher()
        class_names = set(cls.name for cls in visitor.classes)
        for cls in visitor.classes:
            graph.add_dict_to_graph(class_names, cls.call_tree)
        graph.add_classes_to_graph(visitor.classes)
        graph.name = output
        graph.render()
