Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .read command #71

Merged
merged 1 commit into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug Fixes:
Features:
---------

* Added `.read` command for reading scripts.
* Added `.load` command for loading extension libraries. (Thanks: [Zhiming Wang])
* Add support for using `?` as a placeholder in the favorite queries. (Thanks: [Amjith])
* Added shift-tab to select the previous entry in the completion menu. [Amjith]
Expand All @@ -22,8 +23,5 @@ Features:


[Amjith]: https://blog.amjith.com
<<<<<<< HEAD
[Zhiming Wang]: https://github.com/zmwangx
[Irina Truong]: https://github.com/j-bennet
=======
>>>>>>> master
1 change: 1 addition & 0 deletions litecli/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Contributors:
* Thomas Roten
* Zhaolong Zhu
* Zhiming Wang
* Shawn M. Chapla
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, "")]