add new action, text

This commit is contained in:
falsycat 2025-07-19 15:26:32 +09:00
parent ccedff803f
commit 3af69bd931
2 changed files with 14 additions and 0 deletions

View File

@ -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:

View File

@ -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: