add new action, text
This commit is contained in:
parent
ccedff803f
commit
3af69bd931
@ -42,6 +42,13 @@ def create():
|
|||||||
action=_SqlAction,
|
action=_SqlAction,
|
||||||
dest="actions",
|
dest="actions",
|
||||||
)
|
)
|
||||||
|
p.add_argument(
|
||||||
|
"--text",
|
||||||
|
help="outputs any text",
|
||||||
|
nargs=1,
|
||||||
|
action=_TextAction,
|
||||||
|
dest="actions",
|
||||||
|
)
|
||||||
return p
|
return p
|
||||||
|
|
||||||
class _PermanentizeAction(argparse.Action):
|
class _PermanentizeAction(argparse.Action):
|
||||||
@ -60,6 +67,10 @@ class _SqlAction(argparse.Action):
|
|||||||
def __call__(self, parser, ns, values, option_string=None):
|
def __call__(self, parser, ns, values, option_string=None):
|
||||||
_push_action(ns, lambda x: x.sql(values[0]))
|
_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):
|
def _push_action(ns, act):
|
||||||
actions = getattr(ns, "actions", None)
|
actions = getattr(ns, "actions", None)
|
||||||
if actions is None:
|
if actions is None:
|
||||||
|
@ -40,6 +40,9 @@ class Context:
|
|||||||
self.ostream.close()
|
self.ostream.close()
|
||||||
self.ostream = sys.stdout
|
self.ostream = sys.stdout
|
||||||
|
|
||||||
|
def text(self, v):
|
||||||
|
print(v, file=self.ostream)
|
||||||
|
|
||||||
def sql(self, cmd: str):
|
def sql(self, cmd: str):
|
||||||
self.dbcur.execute(cmd)
|
self.dbcur.execute(cmd)
|
||||||
for row in self.dbcur:
|
for row in self.dbcur:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user