Bläddra i källkod

Improved CLI

'invoice show' now invokes a pager, while 'invoice pdf [-g]' is used
to generate and view PDF invoices.
master
Pavel Šimerda 9 år sedan
förälder
incheckning
2d377be221
2 ändrade filer med 20 tillägg och 7 borttagningar
  1. +3
    -1
      README
  2. +17
    -6
      lib/invoice/cli.py

+ 3
- 1
README Visa fil

@@ -48,14 +48,16 @@ Manage companies:


invoice new-company <id> invoice new-company <id>
invoice edit-company <id> invoice edit-company <id>
invoice show-company <id>
invoice delete-company <id> invoice delete-company <id>


Manage invoices: Manage invoices:


invoice new <company-id> invoice new <company-id>
invoice edit [<number>] invoice edit [<number>]
invoice show [<number>]
invoice delete [<number>] invoice delete [<number>]


Generate and display invoice PDF: Generate and display invoice PDF:


invoice show --generate [<number>]
invoice pdf --generate [<number>]

+ 17
- 6
lib/invoice/cli.py Visa fil

@@ -49,19 +49,21 @@ class Application:
help="additional help") help="additional help")


for list_ in "invoices", "companies": for list_ in "invoices", "companies":
for action in "list", "new", "edit", "show", "delete":
for action in "list", "new", "edit", "show", "pdf", "delete":
if action == "pdf" and list_ != "invoices":
continue
suffix = '' suffix = ''
if list_ == "companies": if list_ == "companies":
suffix = "-companies" if action=="list" else "-company" suffix = "-companies" if action=="list" else "-company"
method = getattr(self, "do_"+(action+suffix).replace("-", "_")) method = getattr(self, "do_"+(action+suffix).replace("-", "_"))
subparser = subparsers.add_parser(action+suffix, help=method.__doc__) subparser = subparsers.add_parser(action+suffix, help=method.__doc__)
if method == self.do_show:
if method == self.do_pdf:
subparser.add_argument("--generate", "-g", action="store_true") subparser.add_argument("--generate", "-g", action="store_true")
if action == "delete": if action == "delete":
subparser.add_argument("--force", "-f", action="store_true") subparser.add_argument("--force", "-f", action="store_true")
if action == "new": if action == "new":
subparser.add_argument("name" if suffix else "company_name") subparser.add_argument("name" if suffix else "company_name")
if action in ("show", "edit", "delete"):
if action in ("show", "pdf", "edit", "delete"):
subparser.add_argument("selector", nargs="?") subparser.add_argument("selector", nargs="?")
subparser.set_defaults(method=method) subparser.set_defaults(method=method)


@@ -108,9 +110,18 @@ class Application:
assert os.path.exists(path) assert os.path.exists(path)
subprocess.call((self.editor, path)) subprocess.call((self.editor, path))


def do_show(self, selector, generate):
def do_show(self, selector):
"""View invoice in external viewer.

The external viewer is determined by PAGER environment variable
using 'less' as the default.
"""
item = self.db.invoices[selector]
self._show(item._path)

def do_pdf(self, selector, generate):
"""Generate and view a PDF invoice. """Generate and view a PDF invoice.
This requires Tempita 0.5. This requires Tempita 0.5.
""" """
import tempita import tempita
@@ -198,7 +209,7 @@ class Application:
self._edit(item._path) self._edit(item._path)


def do_show_company(self, selector): def do_show_company(self, selector):
"""View company in external editor.
"""View company in external viewer.


The external viewer is determined by PAGER environment variable The external viewer is determined by PAGER environment variable
using 'less' as the default. using 'less' as the default.


Laddar…
Avbryt
Spara