瀏覽代碼

Improved CLI

'invoice show' now invokes a pager, while 'invoice pdf [-g]' is used
to generate and view PDF invoices.
master
Pavel Šimerda 9 年之前
父節點
當前提交
2d377be221
共有 2 個檔案被更改,包括 20 行新增7 行删除
  1. +3
    -1
      README
  2. +17
    -6
      lib/invoice/cli.py

+ 3
- 1
README 查看文件

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

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

Manage invoices:

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

Generate and display invoice PDF:

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

+ 17
- 6
lib/invoice/cli.py 查看文件

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

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 = ''
if list_ == "companies":
suffix = "-companies" if action=="list" else "-company"
method = getattr(self, "do_"+(action+suffix).replace("-", "_"))
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")
if action == "delete":
subparser.add_argument("--force", "-f", action="store_true")
if action == "new":
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.set_defaults(method=method)

@@ -108,9 +110,18 @@ class Application:
assert os.path.exists(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.
This requires Tempita 0.5.
"""
import tempita
@@ -198,7 +209,7 @@ class Application:
self._edit(item._path)

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
using 'less' as the default.


Loading…
取消
儲存