Skip to content

Commit

Permalink
Add script to call from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
tbm committed Jul 22, 2020
1 parent 9c38b7c commit af5e25f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
45 changes: 45 additions & 0 deletions beancount2ledger/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Beancount to Ledger converter
"""

# SPDX-FileCopyrightText: © 2020 Software in the Public Interest, Inc.
# SPDX-FileCopyrightText: © 2020 Martin Michlmayr <tbm@cyrius.com>

# SPDX-License-Identifier: GPL-2.0-only

__license__ = "GPL-2.0-only"

import argparse
import sys

import beancount2ledger


def cli():
"""
Main function for CLI access.
"""

if "hledger" in sys.argv[0]:
default = "hledger"
else:
default = "ledger"

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'-f',
"--format",
dest="format",
action="store",
choices=("ledger", "hledger"),
default=default,
help=f"output format (default: {default})")
parser.add_argument(
'file', help='beancount file', type=argparse.FileType('r'))
args = parser.parse_args()

print(beancount2ledger.convert_file(args.file.name, args.format))


if __name__ == "__main__":
cli()
1 change: 1 addition & 0 deletions bin/beancount2hledger
14 changes: 14 additions & 0 deletions bin/beancount2ledger
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3

"""
Beancount to Ledger converter
"""

# SPDX-FileCopyrightText: © 2020 Software in the Public Interest, Inc.
# SPDX-FileCopyrightText: © 2020 Martin Michlmayr <tbm@cyrius.com>

# SPDX-License-Identifier: GPL-2.0-only

from beancount2ledger.cli import cli

cli()
1 change: 1 addition & 0 deletions docs/beancount2hledger.1.sdc
48 changes: 48 additions & 0 deletions docs/beancount2ledger.1.sdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
beancount2ledger(1)

; SPDX-FileCopyrightText: © 2020 Martin Michlmayr <tbm@cyrius.com>

; SPDX-License-Identifier: GPL-2.0-only

# NAME

beancount2ledger - beancount to ledger converter

# SYNOPSIS

*beancount2ledger* [options] _input.beancount_ > _output.ledger_

# DESCRIPTION

*beancount2ledger* converts a file in *beancount* format to the *ledger* file format.

# OPTIONS

*-f, --format*
Specify the output format. Allowed values are _ledger_ and _hledger_.

When *beancount2ledger* is called, the default format is _ledger_ whereas the default format is _hledger_ when *beancount2hledger* is called.

*-h, --help*
Show help message and quit.

# USAGE

*beancount2ledger* takes a file argument, loads the file into *beancount* data structures, and converts the data to *ledger* output.

# BUGS

If you find any bugs in *beancount2ledger* or believe the conversion from *beancount* to *ledger* could be improved, please open an issue on GitHub:

https://github.com/beancount/beancount2ledger/issues

Please include a small test case so we can reproduce the problem.

# AUTHORS

Martin Blais, Martin Michlmayr, and others

# SEE ALSO

*ledger*(1), *hledger*(1)

0 comments on commit af5e25f

Please sign in to comment.