summaryrefslogtreecommitdiff
path: root/fracture
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2020-07-26 22:41:55 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2020-07-26 22:41:55 +0200
commitb4efa79f574cc613f819cb1ecf0dbc6571de5720 (patch)
treeee45a7f419b864bbc6aa1fbc0d8792e594ad5941 /fracture
parentb1e27d12c7062b95cb5fa814b98e0055e77ed443 (diff)
Command line argument control
Diffstat (limited to 'fracture')
-rw-r--r--fracture/__main__.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/fracture/__main__.py b/fracture/__main__.py
index b33dca4..4805306 100644
--- a/fracture/__main__.py
+++ b/fracture/__main__.py
@@ -1,6 +1,7 @@
from invoice import Invoice, Tax
import db
+from functools import wraps
from argparse import ArgumentParser as ap
import tempfile
import subprocess
@@ -87,47 +88,59 @@ def edit(contents):
return edited_content
+def command(f):
+ @wraps(f)
+ def remove_func_arg(namespace):
+ kwargs = vars(namespace)
+ del kwargs["func"]
+ f(**kwargs)
+ return remove_func_arg
+
+@command
def edit_config():
# TODO: Generate config file if not created
call_editor(CONFIG_FILE)
+@command
def new_invoice():
num = Invoice.from_config( edit( Invoice().to_config() )).persist()
#
print(num)
# edit(Invoice.load(num).to_config())
-def summarize():
- pass
+@command
+def summarize(xlsx=False, quarter=None, year=None):
+ print(xlsx)
if __name__ == "__main__":
load_config()
-
-
- # create the top-level parser
parser = ap(prog="fracture")
- #parser.add_argument("--foo", action="store_true", help="foo help")
parser.set_defaults(func=lambda: parser.print_help())
-
- # make subparsers
subparsers = parser.add_subparsers(title= "Subcommands",
help="sub-command help")
+ # New Invoice
new_parser = subparsers.add_parser("new", aliases=["n"], help="a help")
new_parser.set_defaults(func=new_invoice)
- configure_parser = subparsers.add_parser("configure", aliases=["c","conf"],
- help="b help")
+ # Configure fracture
+ configure_parser = subparsers.add_parser("configure",
+ aliases=["c","conf","config"],
+ help="b help")
configure_parser.set_defaults(func=edit_config)
-
+ # Summary
summary_parser = subparsers.add_parser("summary", aliases=["s", "sum"],
- help="get summary")
- summary_parser.add_argument("--xlsx", action="store_true", help="aaa")
- summary_parser.add_argument("--quarter", action="store_true", help="aaa")
- summary_parser.add_argument("--year", action="store_true", help="aaa")
+ help="Display summary for tax declarations")
+ summary_parser.add_argument("--xlsx", action="store_true",
+ help="Output as xlsx")
+ summary_parser.add_argument("--quarter", type=int, nargs=1,
+ help="Obtain the summary of the quarter")
+ summary_parser.add_argument("--year", type=int, nargs=1,
+ help="Obtain the summary of the year")
summary_parser.set_defaults(func=summarize)
# parse
- parser.parse_args().func()
+ args = parser.parse_args()
+ args.func(args)