diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2019-08-17 05:56:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-17 05:56:45 -0700 |
commit | fbcd425001a2367d92cc611abf28d46258395b55 (patch) | |
tree | 8f358766fe374352a1af84ac620d16518ee52031 | |
parent | c7947e9bfd06cf39fa0b4839d9831ae055c170a1 (diff) | |
parent | 471525694175e229b7dba3e96293c8e5607e9240 (diff) |
Merge pull request #71 from shwnchpl/read-command
Add .read command
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | litecli/AUTHORS | 1 | ||||
-rw-r--r-- | litecli/packages/special/dbcommands.py | 18 |
3 files changed, 20 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index b35faec..c3f54fe 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,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] diff --git a/litecli/AUTHORS b/litecli/AUTHORS index 073f137..d5265de 100644 --- a/litecli/AUTHORS +++ b/litecli/AUTHORS @@ -17,3 +17,4 @@ Contributors: * Thomas Roten * Zhaolong Zhu * Zhiming Wang + * Shawn M. Chapla diff --git a/litecli/packages/special/dbcommands.py b/litecli/packages/special/dbcommands.py index eefe7e6..bd9f0fd 100644 --- a/litecli/packages/special/dbcommands.py +++ b/litecli/packages/special/dbcommands.py @@ -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, "")] |