Skip to content

Commit

Permalink
Add .read command
Browse files Browse the repository at this point in the history
  • Loading branch information
schapla committed Aug 15, 2019
1 parent 288ae91 commit 80311cf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions litecli/packages/special/dbcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,21 @@ def load_extension(cur, arg, **_):
conn.enable_load_extension(True)
conn.load_extension(path)
return [(None, None, None, "")]


@special_command(
".read",
".read path",
"Read input from path",
arg_type=PARSED_QUERY,
case_sensitive=True,
)
def read_script(cur, arg, **_):
args = shlex.split(arg)
if len(args) != 1:
raise TypeError(".read accepts exactly one path")
path = args[0]
with open(path, 'r') as f:
script = f.read()
cur.executescript(script)
return [(None, None, None, "")]

0 comments on commit 80311cf

Please sign in to comment.