<commit_before>import os
from os import path
import json
import getpass
import glob
import logging
import sys

import pyperclip
import click
from prompt_toolkit import prompt
import configparser

from .api import SnippetApi
from .snippet import Snippet
from .completer import SnippetFilesCompleter
from . import utils

DEFAULT_SNIPPET_DIR = os.path.expanduser('~/.snippets')
DEFAULT_SNIPPER_CONFIG = os.path.expanduser('~/.snipperrc')

@click.group(context_settings={'help_option_names': ['-h', '--help']})
@click.option(
    '--config-file', '-c',
    default=DEFAULT_SNIPPER_CONFIG,
    type=click.Path(),
    help='Config file path: Default: {}'.format(DEFAULT_SNIPPER_CONFIG)
)
@click.pass_context
def cli(context, config_file):

    # Create a SnippetConfig object and remember it as as the context object.  From
    # this point onwards other commands can refer to it by using the
    # @pass_config decorator.

    if not path.exists(config_file):
        click.secho('Configuration file not found. Plase give me your settings.', fg='red')
        init_snipper(config_file=config_file)

    config = configparser.ConfigParser()
    config.read(config_file)

    context.obj = config


def init_snipper(config_file):

    if path.exists(config_file) and not click.confirm('Config file already exist. Overwrite it'):
        return

    snippet_dir = click.prompt('Where to keep snippets', default=DEFAULT_SNIPPET_DIR)
    username = click.prompt('Bitbucket username')
    click.secho(
        """Password using for authenticating to Bitbucket API.<commit_msg>Init config with default settings<commit_after>import os
from os import path
import json
import getpass
import glob
import logging
import sys

import pyperclip
import click
from prompt_toolkit import prompt
import configparser

from .api import SnippetApi
from .snippet import Snippet
from .completer import SnippetFilesCompleter
from . import utils

DEFAULT_SNIPPET_DIR = os.path.expanduser('~/.snippets')
DEFAULT_SNIPPER_CONFIG = os.path.expanduser('~/.snipperrc')

@click.group(context_settings={'help_option_names': ['-h', '--help']})
@click.option(
    '--config-file', '-c',
    default=DEFAULT_SNIPPER_CONFIG,
    type=click.Path(),
    help='Config file path: Default: {}'.format(DEFAULT_SNIPPER_CONFIG)
)
@click.pass_context
def cli(context, config_file):

    if not path.exists(config_file):
        click.secho('Configuration file not found. Plase give me your settings.', fg='red')
        init_snipper(config_file=config_file)

    # Create config with default values
    config = configparser.ConfigParser({
        'snippet_dir': DEFAULT_SNIPPET_DIR,
        'default_filename': 'snippet.md',
        'verbose': 'detailed',
        'auto_push': False,
    })

    # Overwrite config with user config.
    config.read(config_file)

    context.obj = config


def init_snipper(config_file):

    if path.exists(config_file) and not click.confirm('Config file already exist. Overwrite it'):
        return

    snippet_dir = click.prompt('Where to keep snippets', default=DEFAULT_SNIPPET_DIR)
    username = click.prompt('Bitbucket username')
    click.secho(
        """Password using for authenticating to Bitbucket API.
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0, 'mean_word_length': 4.221859706362153, 'pattern_counts': {'":': 0, '<': 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': '2854072', 'n_tokens_mistral': 973, 'n_tokens_neox': 954, 'n_words': 270}