# Path: ledgerbil/ledgershell/runner.py
# def get_ledger_command(args=None):
#     files = []
#     for f in get_setting("LEDGER_FILES"):
#         files += ["-f", os.path.join(get_setting("LEDGER_DIR"), f)]
#     return get_setting("LEDGER_COMMAND") + tuple(files) + (args or ())
# 
# def get_ledger_output(args=None):
#     cmd = get_ledger_command(args)
#     process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
#     output, _ = process.communicate()
#     return output.decode("unicode_escape").rstrip()


import argparse
from textwrap import dedent
from .runner import get_ledger_command, get_ledger_output
    description = dedent(
        """\
        Pass through args to ledger, running ledger with config from
        settings.py
    """
    )
    parser = argparse.ArgumentParser(
        prog=program,
        description=description,
        formatter_class=(
            lambda prog: argparse.RawDescriptionHelpFormatter(
                prog, max_help_position=40, width=71
            )
        ),
    )
    parser.add_argument(
        "--command", action="store_true", help="print ledger command used"
    )
    args, ledger_args = parser.parse_known_args(args)
    return args, tuple(ledger_args)


def main(argv=None):
    args, ledger_args = get_args(argv or [])
    if not ledger_args:
        return 0

    if args.command:
        print(" ".join(get_ledger_command(ledger_args)))


# Path: ledgerbil/ledgershell/runner.py
# def get_ledger_command(args=None):
#     files = []
#     for f in get_setting("LEDGER_FILES"):
#         files += ["-f", os.path.join(get_setting("LEDGER_DIR"), f)]
#     return get_setting("LEDGER_COMMAND") + tuple(files) + (args or ())
# 
# def get_ledger_output(args=None):
#     cmd = get_ledger_command(args)
#     process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
#     output, _ = process.communicate()
#     return output.decode("unicode_escape").rstrip()


# Path: ledgerbil/ledgershell/passthrough.py
import argparse
from textwrap import dedent
from .runner import get_ledger_command, get_ledger_output

    description = dedent(
        """\
        Pass through args to ledger, running ledger with config from
        settings.py
    """
    )
    parser = argparse.ArgumentParser(
        prog=program,
        description=description,
        formatter_class=(
            lambda prog: argparse.RawDescriptionHelpFormatter(
                prog, max_help_position=40, width=71
            )
        ),
    )
    parser.add_argument(
        "--command", action="store_true", help="print ledger command used"
    )
    args, ledger_args = parser.parse_known_args(args)
    return args, tuple(ledger_args)


def main(argv=None):
    args, ledger_args = get_args(argv or [])
    if not ledger_args:
        return 0

    if args.command:
        print(" ".join(get_ledger_command(ledger_args)))


    print(get_ledger_output(ledger_args))