diff --git a/beancount2ledger/cli.py b/beancount2ledger/cli.py new file mode 100644 index 0000000..55c5bd0 --- /dev/null +++ b/beancount2ledger/cli.py @@ -0,0 +1,45 @@ +""" +Beancount to Ledger converter +""" + +# SPDX-FileCopyrightText: © 2020 Software in the Public Interest, Inc. +# SPDX-FileCopyrightText: © 2020 Martin Michlmayr + +# 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() diff --git a/bin/beancount2hledger b/bin/beancount2hledger new file mode 120000 index 0000000..fb33ea6 --- /dev/null +++ b/bin/beancount2hledger @@ -0,0 +1 @@ +beancount2ledger \ No newline at end of file diff --git a/bin/beancount2ledger b/bin/beancount2ledger new file mode 100755 index 0000000..e3608b0 --- /dev/null +++ b/bin/beancount2ledger @@ -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 + +# SPDX-License-Identifier: GPL-2.0-only + +from beancount2ledger.cli import cli + +cli() diff --git a/docs/beancount2hledger.1.sdc b/docs/beancount2hledger.1.sdc new file mode 120000 index 0000000..c3d7971 --- /dev/null +++ b/docs/beancount2hledger.1.sdc @@ -0,0 +1 @@ +beancount2ledger.1.sdc \ No newline at end of file diff --git a/docs/beancount2ledger.1.sdc b/docs/beancount2ledger.1.sdc new file mode 100644 index 0000000..d8d3b18 --- /dev/null +++ b/docs/beancount2ledger.1.sdc @@ -0,0 +1,48 @@ +beancount2ledger(1) + +; SPDX-FileCopyrightText: © 2020 Martin Michlmayr + +; 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) +