# -*- coding: utf-8 -*-
"""
    crimson.main
    ~~~~~~~~~~~~

    Main entry point for command line invocation.

    :copyright: (c) 2015 Wibowo Arindrarto <bow@bow.web.id>
    :license: BSD

"""
import click

from . import __version__
from . import fastqc as m_fastqc
from . import flagstat as m_flagstat
from . import picard as m_picard
from .utils import write_json

__all__ = []


@click.group()
@click.version_option(__version__)
@click.option("--compact", is_flag=True)
@click.pass_context
def cli(ctx, compact):
    """Converts various non-standard bioinformatics tools' output to JSON.

    :param compact: Whether to create a compact JSON output or not.
    :type compact: bool.

    """
    ctx.params["compact"] = compact


@cli.command()
@click.argument("input", type=click.File("r"))
@click.argument("output", type=click.File("w"))
@click.pass_context
def fastqc(ctx, input, output):
    """Converts FastQC output.

    Use "-" for stdin and/or stdout.

    """
    payload = m_fastqc.parse(input)
    write_json(payload, output, ctx.parent.params["compact"])


@cli.command()
@click.argument("input", type=click.File("r"))
@click.argument("output", type=click.File("w"))
@click.pass_context
def flagstat(ctx, input, output):
    """Converts samtools flagstat output.

    Use "-" for stdin and/or stdout.

    """
    payload = m_flagstat.parse(input)
    write_json(payload, output, ctx.parent.params["compact"])


@cli.command()
@click.argument("input", type=click.File("r"))
@click.argument("output", type=click.File("w"))
@click.pass_context
def picard(ctx, input, output):
    """Converts Picard metrics output.

    Use "-" for stdin and/or stdout.

    """
    payload = m_picard.parse(input)
    write_json(payload, output, ctx.parent.params["compact"])

@@ -468,16 +468,130 @@
 lag=True
+,%0A              help=%22Whether to create a compact JSON or not. %22%0A              %22Ignored if output format is YAML.%22
 )%0A@click
@@ -647,29 +647,8 @@
 rts 
-various non-standard 
 bioi
@@ -679,113 +679,26 @@
  to 
-JSON.%0A%0A    :param compact: Whether to create a compact JSON output or not.%0A    :type compact: bool.%0A%0A    
+a standard format.
 %22%22%22%0A

Update main CLI documentation