<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from cider import Cider
from subprocess import CalledProcessError
from webbrowser import open as urlopen
import _tty as tty
import cider
import click
import sys


class CLI(click.Group):
    def __init__(self, **attrs):
        click.Group.__init__(self, **attrs)

    def format_usage(self, ctx, formatter):
        pass

    def format_options(self, ctx, formatter):
        rows = [
            "{0} [cask] install FORMULA...",
            "{0} [cask] rm FORMULA...",
            "{0} [cask] list",
            "{0} [cask] missing",
            "{0} set-default [-g] NAME KEY VALUE",
            "{0} remove-default [-g] NAME KEY",
            "{0} apply-defaults",
            "{0} set-icon APP ICON",
            "{0} remove-icon APP",
            "{0} apply-icons",
            "{0} run-scripts",
            "{0} restore",
            "{0} relink"
        ]

        basename = ctx.command_path
        with formatter.section('Example usage'):
            formatter.write_dl((row.format(basename), '') for row in rows)

    def get_command(self, ctx, cmd_name):
        aliases = {
            "delete": "remove-default",
            "ls": "list",
            "write": "set-default"
        }

        cmd_name = aliases.get(cmd_name, cmd_name)
        return click.Group.get_command(self, ctx, cmd_name)


@click.command(cls=CLI)
def cli():
    pass


@cli.command()
@click.argument("command")
@click.argument("arg", required=False, nargs=-1)
@click.option("-f", "--force", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.pass_context
def cask(ctx, command, arg, force=None, verbose=None, debug=None):
    func_by_cmd = {
        "install": cask_install,
        "rm": cask_rm,
        "missing": cask_missing,
        "list": cask_list
    }

    aliases = {
        "ls": "list",
    }

    args_by_cmd = {
        "install": ["formula", "force", "verbose", "debug"],
        "rm": ["formula", "verbose", "debug"],
        "missing": ["debug"],
        "list": []
    }

    cmd = aliases.get(command, command)
    args = args_by_cmd.get(cmd, [])
    kwargs = {
        "formula": arg,
        "force": force,
        "verbose": verbose,
        "debug": debug
    }
    kwargs = {k: v for k, v in kwargs.iteritems() if k in args}

    func = func_by_cmd.get(cmd)
    if func:
        ctx.invoke(func, **kwargs)
    else:
        raise click.ClickException("No such command \"{0}\"".format(cmd))


@cli.command()
@click.option("-d", "--debug", is_flag=True)
def restore(debug=None):
    Cider(debug).restore()


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def install(formula, debug=None, verbose=None, force=None):
    Cider(debug, verbose).install(force=force, *formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def rm(formula, debug=None, verbose=None):
    Cider(debug, verbose).rm(*formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("tap", required=False)
def tap(tap, debug=None, verbose=None):
    Cider(debug, verbose).tap(tap)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("tap")
def untap(tap, debug=None, verbose=None):
    Cider(debug, verbose).untap(tap)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-f", "--force", is_flag=True)
def relink(debug=None, force=None):
    Cider(debug).relink(force=force)


@cli.command("list")
@click.argument("formula", required=False)
def ls(formula):
    Cider().ls(formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
def missing(debug=None):
    Cider(debug).list_missing()


@cli.command("cask install")
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def cask_install(formula, force=None, debug=None, verbose=None):
    Cider(debug, verbose, cask=True).install(*formula, force=force)


@cli.command("cask rm")
@click.option("-v", "--verbose", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def cask_rm(formula, debug=None, verbose=None):
    Cider(debug, verbose, cask=True).rm(*formula)


@cli.command("cask list")
@click.argument("formula", required=False)
def cask_list(formula):
    Cider(cask=True).ls(formula)


@cli.command("cask missing")
@click.option("-d", "--debug", is_flag=True)
def cask_missing(debug=None):
    Cider(debug, cask=True).list_missing()


@cli.command("set-default")
@click.argument("name")
@click.argument("key")
@click.argument("value")
@click.option("-g", "--globalDomain", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.option("-int", is_flag=True, expose_value=False)
@click.option("-float", is_flag=True, expose_value=False)
@click.option("-string", is_flag=True, expose_value=False)
@click.option("-bool", is_flag=True, expose_value=False)
def set_default(name, key, value, globaldomain=None, force=None, debug=None):
    if globaldomain:
        name, key, value = "NSGlobalDomain", name, key<commit_msg>Fix another bug caught by prospector<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from cider import Cider
from subprocess import CalledProcessError
from webbrowser import open as urlopen
import _tty as tty
import cider
import click
import sys


class CLI(click.Group):
    def __init__(self, **attrs):
        click.Group.__init__(self, **attrs)

    def format_usage(self, ctx, formatter):
        pass

    def format_options(self, ctx, formatter):
        rows = [
            "{0} [cask] install FORMULA...",
            "{0} [cask] rm FORMULA...",
            "{0} [cask] list",
            "{0} [cask] missing",
            "{0} set-default [-g] NAME KEY VALUE",
            "{0} remove-default [-g] NAME KEY",
            "{0} apply-defaults",
            "{0} set-icon APP ICON",
            "{0} remove-icon APP",
            "{0} apply-icons",
            "{0} run-scripts",
            "{0} restore",
            "{0} relink"
        ]

        basename = ctx.command_path
        with formatter.section('Example usage'):
            formatter.write_dl((row.format(basename), '') for row in rows)

    def get_command(self, ctx, cmd_name):
        aliases = {
            "delete": "remove-default",
            "ls": "list",
            "write": "set-default"
        }

        cmd_name = aliases.get(cmd_name, cmd_name)
        return click.Group.get_command(self, ctx, cmd_name)


@click.command(cls=CLI)
def cli():
    pass


@cli.command()
@click.argument("command")
@click.argument("arg", required=False, nargs=-1)
@click.option("-f", "--force", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.pass_context
def cask(ctx, command, arg, force=None, verbose=None, debug=None):
    func_by_cmd = {
        "install": cask_install,
        "rm": cask_rm,
        "missing": cask_missing,
        "list": cask_list
    }

    aliases = {
        "ls": "list",
    }

    args_by_cmd = {
        "install": ["formula", "force", "verbose", "debug"],
        "rm": ["formula", "verbose", "debug"],
        "missing": ["debug"],
        "list": []
    }

    cmd = aliases.get(command, command)
    args = args_by_cmd.get(cmd, [])
    kwargs = {
        "formula": arg,
        "force": force,
        "verbose": verbose,
        "debug": debug
    }
    kwargs = {k: v for k, v in kwargs.iteritems() if k in args}

    func = func_by_cmd.get(cmd)
    if func:
        ctx.invoke(func, **kwargs)
    else:
        raise click.ClickException("No such command \"{0}\"".format(cmd))


@cli.command()
@click.option("-d", "--debug", is_flag=True)
def restore(debug=None):
    Cider(debug).restore()


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def install(formula, debug=None, verbose=None, force=None):
    Cider(debug, verbose).install(force=force, *formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def rm(formula, debug=None, verbose=None):
    Cider(debug, verbose).rm(*formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("tap", required=False)
def tap(tap, debug=None, verbose=None):
    Cider(debug, verbose).tap(tap)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.argument("tap")
def untap(tap, debug=None, verbose=None):
    Cider(debug, verbose).untap(tap)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
@click.option("-f", "--force", is_flag=True)
def relink(debug=None, force=None):
    Cider(debug).relink(force=force)


@cli.command("list")
@click.argument("formula", required=False)
def ls(formula):
    Cider().ls(formula)


@cli.command()
@click.option("-d", "--debug", is_flag=True)
def missing(debug=None):
    Cider(debug).list_missing()


@cli.command("cask install")
@click.option("-d", "--debug", is_flag=True)
@click.option("-v", "--verbose", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def cask_install(formula, force=None, debug=None, verbose=None):
    Cider(True, debug, verbose).install(*formula, force=force)


@cli.command("cask rm")
@click.option("-v", "--verbose", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.argument("formula", nargs=-1, required=True)
def cask_rm(formula, debug=None, verbose=None):
    Cider(True, debug, verbose).rm(*formula)


@cli.command("cask list")
@click.argument("formula", required=False)
def cask_list(formula):
    Cider(cask=True).ls(formula)


@cli.command("cask missing")
@click.option("-d", "--debug", is_flag=True)
def cask_missing(debug=None):
    Cider(True, debug).list_missing()


@cli.command("set-default")
@click.argument("name")
@click.argument("key")
@click.argument("value")
@click.option("-g", "--globalDomain", is_flag=True)
@click.option("-f", "--force", is_flag=True)
@click.option("-d", "--debug", is_flag=True)
@click.option("-int", is_flag=True, expose_value=False)
@click.option("-float", is_flag=True, expose_value=False)
@click.option("-string", is_flag=True, expose_value=False)
@click.option("-bool", is_flag=True, expose_value=False)
def set_default(name, key, value, globaldomain=None, force=None, debug=None):
    if globaldomain:
        name, key, value = "NSGlobalDomain", name, key
{'fraction_non_alphanumeric': 0.19397547538652923, 'fraction_numerical': 0.003554291807357384, 'mean_word_length': 3.6469859620148637, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4279683', 'n_tokens_mistral': 3946, 'n_tokens_neox': 3881, 'n_words': 808}