def pw(
    ctx,
    key_pattern,
    user_pattern,
    mode,
    strict_flag,
    user_flag,
    file,
    edit_subcommand,
    gen_subcommand,
):
    def handle_sigint(*_):
        click.echo()
        ctx.exit(1)
    signal.signal(signal.SIGINT, handle_sigint)
    if gen_subcommand:
        length = int(key_pattern) if key_pattern else None
        generate_password(mode, length)
        return
    elif edit_subcommand:
        launch_editor(ctx, file)
        return
    if not os.path.exists(file):
        click.echo("error: password store not found at '%s'" % file, err=True)
        ctx.exit(1)
    store = Store.load(file)
    if not user_pattern:
        user_pattern, _, key_pattern = key_pattern.rpartition("@")
    results = store.search(key_pattern, user_pattern)
    results = list(results)
    if strict_flag and len(results) != 1:
        click.echo(
            "error: multiple or no records found (but using --strict flag)", err=True
        )
        ctx.exit(2)
    if mode == Mode.RAW:
        for entry in results:
            click.echo(entry.user if user_flag else entry.password)
        return
    for idx, entry in enumerate(results):
        line = highlight_match(key_pattern, entry.key)
        if entry.user:
            line += ": " + highlight_match(user_pattern, entry.user)
        if mode == Mode.ECHO and not user_flag:
            line += " | " + style_password(entry.password)
        elif mode == Mode.COPY and idx == 0:
            try:
                import pyperclip
                pyperclip.copy(entry.user if user_flag else entry.password)
                result = style_success(
                    "*** %s COPIED TO CLIPBOARD ***"
                    % ("USERNAME" if user_flag else "PASSWORD")
                )
            except ImportError:
                result = style_error('*** PYTHON PACKAGE "PYPERCLIP" NOT FOUND ***')
            line += " | " + result
        if entry.notes:
            if idx == 0:
                line += "\n"
                line += "\n".join("   " + line for line in entry.notes.splitlines())
            else:
                lines = entry.notes.splitlines()
                line += " | " + lines[0]
                if len(lines) > 1:
                    line += " (...)"
        click.echo(line)