import argparse
import json
import shlex

import click

import mucus.command


class Command(mucus.command.Command):
    def __call__(self, client, command, **kwargs):
        parser = argparse.ArgumentParser(add_help=False, exit_on_error=False)
        parser.add_argument('-j', '--json', action='store_true')
        try:
            args = parser.parse_args(shlex.split(command['args']))
        except argparse.ArgumentError as e:
            raise mucus.exception.CommandException(e)

        if args.json:
            click.echo(json.dumps(client.data._data, indent=2))
        else:
            click.echo(client.data._data['USER']['EMAIL'])
