Code Monkey home page Code Monkey logo

autobean-format's Introduction

autobean-format

build pypi Test Coverage Maintainability license

Yet another formatter for beancount.

Features

  • Deep cleanup.
    • Normalizes all spacing.
    • Full beancount v2 syntax support (except out-of-line tags / links in transaction).
  • Currency / cost aligning.
    • Works for open, balance, price and posting.
  • Entry sorting.
    • Honors pushtag / pushmeta.
    • Honors time meta (HH:MM / HH:MM:SS / epoch seconds / epoch ms / epoch us).
    • Preserves comments.
    • Preserves existing structure and ordering whenever possible.
  • Thousands separator normalization.
    • Adds / removes / keeps thousands separators.
  • Recursive formatting.
    • Recursively formats included files.
    • Honors glob includes.
  • Flexible output.
    • Prints results / prints diff / writes back to file.
  • Typed and extensible.
    • For example, the code for thousands separators is as simple as this.

Usage

pip install autobean-format

# format and print results
autobean-format foo.bean
# format and write back to file
autobean-format foo.bean --output-mode=inplace
# format and print the diff
autobean-format foo.bean --output-mode=diff

# sort entries by date and time
autobean-format foo.bean --sort

# recursively format all included files
autobean-format foo.bean --recursive

# add thousands separators to all numbers
autobean-format foo.bean --thousands-separator=add

# see more options
autobean-format -h

Examples

autobean-format foo.bean \
    --indent='    ' \
    --currency-column=30 \
    --cost-column=35 \
    --thousands-separator=add \
    --spaces-in-braces \
    --sort \
    --recursive \
    --output-mode=inplace
Before After

foo.bean:

2000-01-01 open Assets:Foo USD,XXX
2000-01-01  *  "foo"   ^aa  #bb
  meta:123
     Assets:Foo  -1.23*4000USD    ;X
    Assets:Foo 1000 XXX {4.92  USD}
   meta:456


include "price.*"
2000-01-02 balance Assets:Foo -4920USD
2000-01-02 balance Assets:Foo 1000XXX

price.bean:

2021-01-01 price EUR 1.21 USD
 ;inner comment
2021-01-04 price GBP  1.36 USD  ; Y
;leading comment
2021-01-01 price JPY  0.009 USD

2020-01-01 price EUR  1.12 USD
2020-01-02 price GBP  1.32USD
2020-01-01 price JPY  0.009 USD

foo.bean:

2000-01-01 open Assets:Foo    USD, XXX

2000-01-01 * "foo" ^aa #bb
    meta: 123
    Assets:Foo  -1.23 * 4,000 USD ; X
    Assets:Foo          1,000 XXX  { 4.92 USD }
        meta: 456

include "price.*"

2000-01-02 balance Assets:Foo -4,920 USD
2000-01-02 balance Assets:Foo 1,000 XXX

price.bean:

2020-01-01 price EUR     1.12 USD
2020-01-01 price JPY    0.009 USD
2020-01-02 price GBP     1.32 USD

2021-01-01 price EUR     1.21 USD
    ; inner comment
; leading comment
2021-01-01 price JPY    0.009 USD
2021-01-04 price GBP     1.36 USD ; Y

autobean-format's People

Contributors

redstreet avatar seiarotg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.