Interpolate complete help doc of given object

    Assumption that given object as a specific interface:

    obj.__doc__ is the basic help object.
    obj.get_actions_titles() returns the subcommand if any.

def get_help(obj, env, subcmds):
    """Interpolate complete help doc of given object

    Assumption that given object as a specific interface:

    obj.__doc__ is the basic help object.
    obj.get_actions_titles() returns the subcommand if any.


    """
    doc = txt.dedent(obj.__doc__ or "")
    env = env.copy()  ## get a local copy

    doc = doc.strip()
    if not re.search(r"^usage:\s*$", doc, flags=re.IGNORECASE | re.MULTILINE):
        doc += txt.dedent("""

            Usage:
              %(std_usage)s

            Options:
              %(std_options)s""")

    help_line = ("  %%-%ds  %%s"
                 % (max([5] + [len(a) for a in subcmds]), ))
    env["actions"] = "\n".join(
        help_line % (
            name,
            get_help(subcmd, subcmd_env(env, name), {}).split("\n")[0])
        for name, subcmd in subcmds.items())
    env["actions_help"] = "" if not env["actions"] else (
        "ACTION could be one of:\n\n"
        "%(actions)s\n\n"
        "See '%(surcmd)s help ACTION' for more information "
        "on a specific command."
        % env)
    if "%(std_usage)s" in doc:
        env["std_usage"] = txt.indent(
            ("%(surcmd)s --help\n"
             "%(surcmd)s --version" +
             (("\n%(surcmd)s help [COMMAND]"
               "\n%(surcmd)s ACTION [ARGS...]") if subcmds else ""))
            % env,
            _find_prefix(doc, "%(std_usage)s"),
            first="")
    if "%(std_options)s" in doc:
        env["std_options"] = txt.indent(
            "--help          Show this screen.\n"
            "--version       Show version.",
            _find_prefix(doc, "%(std_options)s"),
            first="")

    if subcmds and "%(actions_help)s" not in doc:
        doc += "\n\n%(actions_help)s"
    try:
        output = doc % env
    except KeyError as e:
        msg.err("Doc interpolation of %s needed missing key %r"
                % (aformat(env["surcmd"], attrs=["bold", ]),
                   e.args[0]))
        exit(1)
    except Exception as e:
        msg.err(
            "Documentation of %s is not valid. Please check it:\n%s"
            % (aformat(env["surcmd"], attrs=["bold", ]),
               doc))
        exit(1)
    return output