Inits a dynaconf project
    By default it creates a settings.toml and a .secrets.toml
    for [default|development|staging|testing|production|global] envs.

    The format of the files can be changed passing
    --format=yaml|json|ini|py.

    This command must run on the project's root folder or you must pass
    --path=/myproject/root/folder.

    If you want to have a .env created with the ENV defined there e.g:
    `ENV_FOR_DYNACONF=production` just pass --env=production and then .env
    will also be created and the env defined to production.

def init(fileformat, path, env, _vars, _secrets, wg, y, django):
    """Inits a dynaconf project
    By default it creates a settings.toml and a .secrets.toml
    for [default|development|staging|testing|production|global] envs.

    The format of the files can be changed passing
    --format=yaml|json|ini|py.

    This command must run on the project's root folder or you must pass
    --path=/myproject/root/folder.

    If you want to have a .env created with the ENV defined there e.g:
    `ENV_FOR_DYNACONF=production` just pass --env=production and then .env
    will also be created and the env defined to production.
    """
    click.echo("Cofiguring your Dynaconf environment")

    env = env or settings.current_env.lower()

    loader = importlib.import_module(
        "dynaconf.loaders.{}_loader".format(fileformat)
    )
    # Turn foo=bar=zaz in {'foo': 'bar=zaz'}
    env_data = split_vars(_vars)
    _secrets = split_vars(_secrets)

    # create placeholder data for every env
    settings_data = {k: {"value": "value for {}".format(k)} for k in ENVS}
    secrets_data = {k: {"secret": "secret for {}".format(k)} for k in ENVS}
    if env_data:
        settings_data[env] = env_data
        settings_data["default"] = {k: "default" for k in env_data}
    if _secrets:
        secrets_data[env] = _secrets
        secrets_data["default"] = {k: "default" for k in _secrets}

    path = Path(path)

    if str(path).endswith(
        constants.ALL_EXTENSIONS + ("py",)
    ):  # pragma: no cover  # noqa
        settings_path = path
        secrets_path = path.parent / ".secrets.{}".format(fileformat)
        dotenv_path = path.parent / ".env"
        gitignore_path = path.parent / ".gitignore"
    else:
        if fileformat == "env":
            if str(path) in (".env", "./.env"):  # pragma: no cover
                settings_path = path
            elif str(path).endswith("/.env"):  # pragma: no cover
                settings_path = path
            elif str(path).endswith(".env"):  # pragma: no cover
                settings_path = path.parent / ".env"
            else:
                settings_path = path / ".env"
            Path.touch(settings_path)
            secrets_path = None
        else:
            settings_path = path / "settings.{}".format(fileformat)
            secrets_path = path / ".secrets.{}".format(fileformat)
        dotenv_path = path / ".env"
        gitignore_path = path / ".gitignore"

    if fileformat in ["py", "env"]:
        # for Python and .env files writes a single env
        settings_data = settings_data[env]
        secrets_data = secrets_data[env]

    if not y and settings_path and settings_path.exists():  # pragma: no cover
        click.confirm(
            "{} exists do you want to overwrite it?".format(settings_path),
            abort=True,
        )

    if not y and secrets_path and secrets_path.exists():  # pragma: no cover
        click.confirm(
            "{} exists do you want to overwrite it?".format(secrets_path),
            abort=True,
        )

    if settings_path and settings_data:
        loader.write(settings_path, settings_data, merge=True)
    if secrets_path and secrets_data:
        loader.write(secrets_path, secrets_data, merge=True)

    # write .env file
    # if env not in ['default', 'development']:  # pragma: no cover
    if not dotenv_path.exists():  # pragma: no cover
        Path.touch(dotenv_path)
        dotenv_cli.set_key(str(dotenv_path), "ENV_FOR_DYNACONF", env.upper())
    else:  # pragma: no cover
        click.echo(
            ".env already exists please set ENV_FOR_DYNACONF={}".format(
                env.upper()
            )
        )

    if wg:
        # write .gitignore
        ignore_line = ".secrets.*"
        comment = "\n# Ignore dynaconf secret files\n"
        if not gitignore_path.exists():
            with io.open(str(gitignore_path), "w", encoding=ENC) as f:
                f.writelines([comment, ignore_line, "\n"])
        else:
            existing = (
                ignore_line
                in io.open(str(gitignore_path), encoding=ENC).read()
            )
            if not existing:  # pragma: no cover
                with io.open(str(gitignore_path), "a+", encoding=ENC) as f:
                    f.writelines([comment, ignore_line, "\n"])

    if django:  # pragma: no cover
        dj_module, loaded_from = get_module({}, django)
        dj_filename = dj_module.__file__
        if Path(dj_filename).exists():
            click.confirm(
                "{} is found do you want to add dynaconf?".format(dj_filename),
                abort=True,
            )
            with open(dj_filename, "a") as dj_file:
                dj_file.write(constants.DJANGO_PATCH)
        else:
            click.echo("Django settings file not written.")