pylipp / financeager

Organize your finances easily - from the command line!
GNU General Public License v3.0
82 stars 22 forks source link

Provide command line argument completion #47

Closed pylipp closed 4 years ago

pylipp commented 5 years ago

E.g. using argcomplete

diff --git a/financeager/cli.py b/financeager/cli.py
index d972c0a..b0ac2d0 100644
--- a/financeager/cli.py
+++ b/financeager/cli.py
@@ -5,6 +5,8 @@ import argparse
 import os
 import sys

+import argcomplete
+
 from financeager import offline, communication, __version__,\
     init_logger, make_log_stream_handler_verbose, setup_log_file_handler
 import financeager
@@ -26,13 +28,14 @@ def main():
     directory are created. A FileHandler is added to the package logger.
     All command line arguments and options are parsed and passed to 'run()'.
     """
+    args = _parse_command()
     os.makedirs(financeager.DATA_DIR, exist_ok=True)

     # Adding the FileHandler here avoids cluttering the log during tests
     setup_log_file_handler()

     # Most runs return None which evaluates to return code 0
-    sys.exit(run(**_parse_command()))
+    sys.exit(run(**args))

 def run(command=None, config=None, verbose=False, **cl_kwargs):
@@ -251,6 +254,7 @@ least a frequency, start date and end date are optional. Default:
             subparser.add_argument(
                 "-p", "--period", help="name of period to modify or query")

+    argcomplete.autocomplete(parser)
     return vars(parser.parse_args(args=args))