8000 option --precision is added by Ev2geny · Pull Request #120 · beancount/beanprice · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

option --precision is added #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion beanprice/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ def process_args() -> Tuple[
entries: A list of all the parsed entries.
dcontext: A context used to determine decimal precision when printing.
"""
parser = argparse.ArgumentParser(description=beanprice.__doc__.splitlines()[0])
parser = argparse.ArgumentParser(description=beanprice.__doc__.splitlines()[0],
formatter_class=argparse.RawTextHelpFormatter)

# Input sources or filenames.
parser.add_argument(
Expand Down Expand Up @@ -822,6 +823,22 @@ def process_args() -> Tuple[
),
)

# Using str type here instead of bool to allow for future expansion of
# precision options.
parser.add_argument(
"-p",
"--precision",
type=str,
choices=['std', 'raw'],
default="std",
help=(
"Defines the approach to determine the precision with which prices are printed"
" (default: %(default)s).\n"
"std - standard beancount approach \n"
"raw - print the prices with the precision, received from the data source \n"
),
)

# Caching options.
cache_group = parser.add_argument_group("cache")
cache_filename = path.join(
Expand Down Expand Up @@ -977,6 +994,16 @@ def main():
logging.info("Ignored to avoid clobber: %s %s", entry.date, entry.currency)

# Print out the entries.

if args.precision == "raw":
dcontext = None

elif args.precision == "std":
pass

else:
raise ValueError(f"Invalid precision option: {args.precision}")

printer.print_entries(price_entries, dcontext=dcontext)

if __name__ == '__main__':
Expand Down
0