From 3af69bd931a636b896505ed8a80db4f4a5329929 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sat, 19 Jul 2025 15:26:32 +0900 Subject: [PATCH] add new action, text --- bookeeper/args.py | 11 +++++++++++ bookeeper/ctx.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/bookeeper/args.py b/bookeeper/args.py index 94089d6..1f1ffc4 100644 --- a/bookeeper/args.py +++ b/bookeeper/args.py @@ -42,6 +42,13 @@ def create(): action=_SqlAction, dest="actions", ) + p.add_argument( + "--text", + help="outputs any text", + nargs=1, + action=_TextAction, + dest="actions", + ) return p class _PermanentizeAction(argparse.Action): @@ -60,6 +67,10 @@ class _SqlAction(argparse.Action): def __call__(self, parser, ns, values, option_string=None): _push_action(ns, lambda x: x.sql(values[0])) +class _TextAction(argparse.Action): + def __call__(self, parser, ns, values, option_string=None): + _push_action(ns, lambda x: x.text(values[0])) + def _push_action(ns, act): actions = getattr(ns, "actions", None) if actions is None: diff --git a/bookeeper/ctx.py b/bookeeper/ctx.py index f5172ce..1f33789 100644 --- a/bookeeper/ctx.py +++ b/bookeeper/ctx.py @@ -40,6 +40,9 @@ class Context: self.ostream.close() self.ostream = sys.stdout + def text(self, v): + print(v, file=self.ostream) + def sql(self, cmd: str): self.dbcur.execute(cmd) for row in self.dbcur: