summaryrefslogtreecommitdiff
path: root/fracture/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'fracture/__main__.py')
-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)