#!/usr/bin/env python3
from xdg import BaseDirectory
import os
import sys


def get_app_dir(sub_dir='') -> str:
    """Return the path to the XDG dir or exit 1."""
    xdg_dir = BaseDirectory.save_data_path('ietf')
    want_dir = os.path.join(xdg_dir, sub_dir)
    # Ensure that the directory exists
    if not os.path.isdir(want_dir):
        print("'{}' is not a directory.  "
              "Run the `mirror` subcommand to create it."
              .format(want_dir))
        sys.exit(1)
    return want_dir


def get_db_path(no_warn=False) -> str:
    """Return the path to the database."""
    xdg_dir = BaseDirectory.save_data_path('ietf')
    db_path = os.path.join(xdg_dir, 'rfc-index.sqlite3')
    # Ensure that the file exists
    if (not os.path.isfile(db_path)) and (not no_warn):
        print("The database at '{}' does not exist.  "
              "Run the `mirror` subcommand to create it."
              .format(db_path))
        sys.exit(1)
    return db_path


def get_pager():
    """Return $PAGER if it exists or exit 2."""
    pager = os.environ.get('PAGER', -1)
    if isinstance(pager, int):
        print('No value for $PAGER found in environment. '
              'Export PAGER then rerun.')
        sys.exit(2)
    pager_cmd = pager.split()  # Split the returned string into a list
    return pager_cmd


def get_editor():
    """Return $EDITOR if it exists or exit 2."""
    editor = os.environ.get('EDITOR', -1)
    if isinstance(editor, int):
        print('No value for $EDITOR found in environment. '
              'Export EDITOR then rerun.')
        sys.exit(2)
    editor_cmd = editor.split()  # Split the returned string into a list
    return editor_cmd

@@ -16,16 +16,132 @@
 python3%0A
+from ietf.sql.bcp import Bcp%0Afrom ietf.sql.fyi import Fyi%0Afrom ietf.sql.rfc import Rfc%0Afrom ietf.sql.std import Std%0A
 from xdg
@@ -1793,12 +1793,1145 @@
  editor_cmd%0A
+%0A%0Adef get_file(document):%0A    %22%22%22Return the path for the given document.%22%22%22%0A    doc_id = document.id%0A    if isinstance(document, Bcp):%0A        bcp_dir = get_app_dir('rfc/bcp')%0A        bcp_file = os.path.join(bcp_dir, %22bcp%7B%7D.txt%22.format(doc_id))%0A        if not os.path.isfile(bcp_file):%0A            return None%0A        else:%0A            return bcp_file%0A    elif isinstance(document, Fyi):%0A        fyi_dir = get_app_dir('rfc/fyi')%0A        fyi_file = os.path.join(fyi_dir, %22fyi%7B%7D.txt%22.format(doc_id))%0A        if not os.path.isfile(fyi_file):%0A            return None%0A        else:%0A            return fyi_file%0A    elif isinstance(document, Rfc):%0A        rfc_dir = get_app_dir('rfc')%0A        rfc_file = os.path.join(rfc_dir, %22rfc%7B%7D.txt%22.format(doc_id))%0A        if not os.path.isfile(rfc_file):%0A            return None%0A        else:%0A            return rfc_file%0A    elif isinstance(document, Std):%0A        std_dir = get_app_dir('std')%0A        std_file = os.path.join(std_dir, %22std%7B%7D.txt%22.format(doc_id))%0A        if not os.path.isfile(std_file):%0A            return None%0A        else:%0A            return std_file%0A    else:%0A        return None%0A

Add `get_file()`