From bbc60b0e01366e616436b13f8182ec3e840f5b84 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 29 Feb 2020 18:26:32 +0100 Subject: [PATCH] Update docs and reorder commands --- README.md | 11 +++++++---- ofx_processor/main.py | 4 ++-- ofx_processor/processors/bpvf.py | 3 ++- ofx_processor/processors/ce.py | 3 ++- ofx_processor/processors/revolut.py | 3 ++- ofx_processor/utils/utils.py | 11 +++++++++++ ofx_processor/utils/ynab.py | 4 +--- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c875068..b7a9a68 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,18 @@ ```shell script Usage: ynab [OPTIONS] COMMAND [ARGS]... + Import your data to YNAB with the processors listed below or manage your + config. + Options: --version Show the version and exit. -h, --help Show this message and exit. Commands: - bpvf Process BPVF bank statement (OFX) - ce Process CE bank statement (OFX) - config - revolut Process Revolut bank statement (CSV) + config Manage configuration. + bpvf Import BPVF bank statement (OFX file). + ce Import CE bank statement (OFX file). + revolut Import Revolut bank statement (CSV file). ``` All transactions will be pushed to YNAB. If this is your first time using the script, diff --git a/ofx_processor/main.py b/ofx_processor/main.py index 7f3075a..e109bbc 100644 --- a/ofx_processor/main.py +++ b/ofx_processor/main.py @@ -1,12 +1,12 @@ import click from ofx_processor.utils import ynab -from ofx_processor.utils.utils import discover_processors +from ofx_processor.utils.utils import discover_processors, OrderedGroup CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) -@click.group(context_settings=CONTEXT_SETTINGS) +@click.group(context_settings=CONTEXT_SETTINGS, cls=OrderedGroup) @click.version_option() def cli(): """ diff --git a/ofx_processor/processors/bpvf.py b/ofx_processor/processors/bpvf.py index 271b3b4..16dd90f 100644 --- a/ofx_processor/processors/bpvf.py +++ b/ofx_processor/processors/bpvf.py @@ -57,7 +57,8 @@ class BpvfProcessor(Processor): return ofx.statements[0].transactions @staticmethod - @click.command("bpvf", help="Process BPVF bank statement (OFX)") + @click.command("bpvf") @click.argument("ofx_filename") def main(ofx_filename): + """Import BPVF bank statement (OFX file).""" BpvfProcessor(ofx_filename).push_to_ynab() diff --git a/ofx_processor/processors/ce.py b/ofx_processor/processors/ce.py index 28fd032..bba8552 100644 --- a/ofx_processor/processors/ce.py +++ b/ofx_processor/processors/ce.py @@ -25,7 +25,8 @@ class CeProcessor(BpvfProcessor): line_class = CeLine @staticmethod - @click.command("ce", help="Process CE bank statement (OFX)") + @click.command("ce") @click.argument("ofx_filename") def main(ofx_filename): + """Import CE bank statement (OFX file).""" CeProcessor(ofx_filename).push_to_ynab() diff --git a/ofx_processor/processors/revolut.py b/ofx_processor/processors/revolut.py index d0aa187..4387886 100644 --- a/ofx_processor/processors/revolut.py +++ b/ofx_processor/processors/revolut.py @@ -62,7 +62,8 @@ class RevolutProcessor(Processor): sys.exit(1) @staticmethod - @click.command("revolut", help="Process Revolut bank statement (CSV)") + @click.command("revolut") @click.argument("csv_filename") def main(csv_filename): + """Import Revolut bank statement (CSV file).""" RevolutProcessor(csv_filename).push_to_ynab() diff --git a/ofx_processor/utils/utils.py b/ofx_processor/utils/utils.py index bb41782..d103e7e 100644 --- a/ofx_processor/utils/utils.py +++ b/ofx_processor/utils/utils.py @@ -1,3 +1,4 @@ +import collections import importlib import pkgutil @@ -25,3 +26,13 @@ def discover_processors(cli: click.Group): if item.endswith("Processor") and item != "Processor": cls = getattr(module, item) cli.add_command(cls.main) + + +class OrderedGroup(click.Group): + def __init__(self, name=None, commands=None, **attrs): + super(OrderedGroup, self).__init__(name, commands, **attrs) + #: the registered subcommands by their exported names. + self.commands = commands or collections.OrderedDict() + + def list_commands(self, ctx): + return self.commands diff --git a/ofx_processor/utils/ynab.py b/ofx_processor/utils/ynab.py index 1e346cb..1c18f71 100644 --- a/ofx_processor/utils/ynab.py +++ b/ofx_processor/utils/ynab.py @@ -30,9 +30,7 @@ def get_config_file_name(): @click.group() def config(): - """ - Manage configuration with subcommands - """ + """Manage configuration.""" @config.command("edit")