<commit_before>import click
import sys

from . import package_utils
from click_plugins import with_plugins
from pkg_resources import iter_entry_points


@with_plugins(iter_entry_points('stakkr.plugins'))
@click.group(help="""Main CLI Tool that easily create / maintain
a stack of services, for example for web development.

Read the configuration file and setup the required services by
linking and managing everything for you.""")
@click.version_option('3.0')
@click.option('--config', '-c', help='Change the configuration file')
@click.option('--debug/--no-debug', '-d', default=False)
@click.option('--verbose', '-v', is_flag=True)
@click.pass_context
def stakkr(ctx, config, debug, verbose):
    from stakkr.actions import StakkrActions

    # Add the virtual env in the path
    venv_base = package_utils.get_venv_basedir()
    sys.path.append(venv_base)

    ctx.obj['CONFIG'] = config
    ctx.obj['DEBUG'] = debug
    ctx.obj['VERBOSE'] = verbose
    ctx.obj['STAKKR'] = StakkrActions(venv_base, ctx.obj)


@stakkr.command(help="""Enter a container to perform direct actions such as install packages, run commands ...

Valid values for CONTAINER : 'apache', 'mysql' or 'php'""")
@click.option('--user', '-u', help="User's name. Valid choices : www-data or root",
              type=click.Choice(['www-data', 'root']))
@click.argument('container', required=True, type=click.Choice(['apache', 'mysql', 'python', 'php']))
@click.pass_context
def console(ctx, container: str, user: str):
    if container in ['php', 'apache'] and user is None:
        user = 'www-data'
    elif container not in ['php', 'apache'] and user == 'www-data':
        user = 'root'
    elif user is None:
        user = 'root'

    stakkr = ctx.obj['STAKKR']
    stakkr.console(container, user)


@stakkr.command(
    help="""Start or Stop the DNS forwarder.
Only one DNS Forwarded by host is possible. Done with mgood/resolvable.

Valid values for ACTION : 'start' or 'stop'""",
    name="dns"
    )
@click.argument('action', required=True, type=click.Choice(['start', 'stop']))
@click.pass_context
def dns(ctx, action: str):
    stakkr = ctx.obj['STAKKR']

    if action == 'start':
        str_action = 'Starting'
    elif action == 'stop':
        str_action = 'Stopping'

    print(click.style('[{}]'.format(str_action).upper(), fg='green') + ' DNS forwarder ...')
    stakkr.manage_dns(action)



@stakkr.command(help="""Execute a command into a container.

Examples:

- ``stakkr exec mysql env | grep PASS`` : get mysql password

- ``stakkr exec mysql mysqldump -p mydb > /tmp/backup.sql``

- ``stakkr exec php php -v`` : Execute the php binary in the php container with option -v

- ``stakkr exec apache service apache2 restart``

""",
    context_settings=dict(ignore_unknown_options=True))
@click.pass_context
@click.option('--user', '-u', help="User's name. Be careful, each container have its own users.")
@click.argument('container', required=True)
@click.argument('command', required=True, nargs=-1, type=click.UNPROCESSED)
def exec(ctx, user: str, container: str, command: tuple):
    users = {
        'php': 'www-data'
    }
    if user is None:
        user = users[container] if container in users else 'root'

    ctx.obj['STAKKR'].exec(container, user, ' '.join(command))


@stakkr.command(
    help="""`stakkr mysql` is a wrapper for the mysql binary located in the mysql service.

You can run any mysql command as root, such as :

- ``stakkr mysql -e "CREATE DATABASE mydb"`` to create a DB from outside

- ``stakkr mysql`` to enter the mysql console

- ``cat myfile.sql | stakkr mysql mydb`` to import a file from outside to mysql


For scripts, you must use the relative path.
""",
    context_settings=dict(ignore_unknown_options=True))
@click.pass_context
@click.argument('command', nargs=-1, type=click.UNPROCESSED)
def mysql(ctx, command: tuple):
    ctx.obj['STAKKR'].run_mysql(' '.join(command))
<commit_msg>Replace new lines by \n<commit_after>import click
import sys

from . import package_utils
from click_plugins import with_plugins
from pkg_resources import iter_entry_points


@with_plugins(iter_entry_points('stakkr.plugins'))
@click.group(help="""Main CLI Tool that easily create / maintain
a stack of services, for example for web development.

Read the configuration file and setup the required services by
linking and managing everything for you.""")
@click.version_option('3.0')
@click.option('--config', '-c', help='Change the configuration file')
@click.option('--debug/--no-debug', '-d', default=False)
@click.option('--verbose', '-v', is_flag=True)
@click.pass_context
def stakkr(ctx, config, debug, verbose):
    from stakkr.actions import StakkrActions

    # Add the virtual env in the path
    venv_base = package_utils.get_venv_basedir()
    sys.path.append(venv_base)

    ctx.obj['CONFIG'] = config
    ctx.obj['DEBUG'] = debug
    ctx.obj['VERBOSE'] = verbose
    ctx.obj['STAKKR'] = StakkrActions(venv_base, ctx.obj)


@stakkr.command(help="""Enter a container to perform direct actions such as install packages, run commands ...

Valid values for CONTAINER : 'apache', 'mysql' or 'php'""")
@click.option('--user', '-u', help="User's name. Valid choices : www-data or root",
              type=click.Choice(['www-data', 'root']))
@click.argument('container', required=True, type=click.Choice(['apache', 'mysql', 'python', 'php']))
@click.pass_context
def console(ctx, container: str, user: str):
    if container in ['php', 'apache'] and user is None:
        user = 'www-data'
    elif container not in ['php', 'apache'] and user == 'www-data':
        user = 'root'
    elif user is None:
        user = 'root'

    stakkr = ctx.obj['STAKKR']
    stakkr.console(container, user)


@stakkr.command(
    help="""Start or Stop the DNS forwarder.
Only one DNS Forwarded by host is possible. Done with mgood/resolvable.

Valid values for ACTION : 'start' or 'stop'""",
    name="dns"
    )
@click.argument('action', required=True, type=click.Choice(['start', 'stop']))
@click.pass_context
def dns(ctx, action: str):
    stakkr = ctx.obj['STAKKR']

    if action == 'start':
        str_action = 'Starting'
    elif action == 'stop':
        str_action = 'Stopping'

    print(click.style('[{}]'.format(str_action).upper(), fg='green') + ' DNS forwarder ...')
    stakkr.manage_dns(action)



@stakkr.command(help="""Execute a command into a container.

Examples:\n
- ``stakkr exec mysql env | grep PASS`` : get mysql password\n
- ``stakkr exec mysql mysqldump -p mydb > /tmp/backup.sql``\n
- ``stakkr exec php php -v`` : Execute the php binary in the php container with option -v\n
- ``stakkr exec apache service apache2 restart``\n
""",
    context_settings=dict(ignore_unknown_options=True))
@click.pass_context
@click.option('--user', '-u', help="User's name. Be careful, each container have its own users.")
@click.argument('container', required=True)
@click.argument('command', required=True, nargs=-1, type=click.UNPROCESSED)
def exec(ctx, user: str, container: str, command: tuple):
    users = {
        'php': 'www-data'
    }
    if user is None:
        user = users[container] if container in users else 'root'

    ctx.obj['STAKKR'].exec(container, user, ' '.join(command))


@stakkr.command(
    help="""`stakkr mysql` is a wrapper for the mysql binary located in the mysql service.

You can run any mysql command as root, such as :\n
- ``stakkr mysql -e "CREATE DATABASE mydb"`` to create a DB from outside\n
- ``stakkr mysql`` to enter the mysql console\n
- ``cat myfile.sql | stakkr mysql mydb`` to import a file from outside to mysql\n

For scripts, you must use the relative path.
""",
    context_settings=dict(ignore_unknown_options=True))
@click.pass_context
@click.argument('command', nargs=-1, type=click.UNPROCESSED)
def mysql(ctx, command: tuple):
    ctx.obj['STAKKR'].run_mysql(' '.join(command))

{'fraction_non_alphanumeric': 0.14632904949739153, 'fraction_numerical': 0.001272426517368622, 'mean_word_length': 4.137254901960785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, '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': '4350656', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2472, 'n_words': 777}