From 10a447cd075bb2734edd49f8166685513c2359bf Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 30 Nov 2020 22:01:23 -0800 Subject: [PATCH] Add argument read_files so that arg may be a filepath. --- voussoirkit/pipeable.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/voussoirkit/pipeable.py b/voussoirkit/pipeable.py index ba7452c..4d5d851 100644 --- a/voussoirkit/pipeable.py +++ b/voussoirkit/pipeable.py @@ -1,4 +1,5 @@ # import pyperclip moved to stay lazy. +import os import sys builtin_input = input @@ -49,7 +50,14 @@ def multi_line_input(prompt=None): if has_eof: break -def input(arg=None, *, input_prompt=None, skip_blank=False, strip=False): +def input( + arg=None, + *, + input_prompt=None, + read_files=False, + skip_blank=False, + strip=False, + ): if arg is not None: arg_lower = arg.lower() @@ -72,6 +80,9 @@ def input(arg=None, *, input_prompt=None, skip_blank=False, strip=False): import pyperclip lines = pyperclip.paste().splitlines() + elif read_files and os.path.isfile(arg): + lines = open(arg, 'r', encoding='utf-8') + else: lines = arg.splitlines()