From 471525694175e229b7dba3e96293c8e5607e9240 Mon Sep 17 00:00:00 2001 From: Shawn Chapla Date: Wed, 14 Aug 2019 22:51:00 -0400 Subject: [PATCH] Add .read command --- changelog.md | 4 +--- litecli/AUTHORS | 1 + litecli/packages/special/dbcommands.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index f97afe8..0d10ba0 100644 --- a/changelog.md +++ b/changelog.md @@ -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] @@ -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 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, "")]