From 43c0631f9b5f595db0a9646bc9d043606f23ec9e Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 17 Aug 2020 11:45:42 +0100 Subject: [PATCH] add non interactive modes to build scripts --- mail/generate.py | 21 ++++++++++++++++----- scss/compile.py | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/mail/generate.py b/mail/generate.py index 84c1dd9..1772ba7 100755 --- a/mail/generate.py +++ b/mail/generate.py @@ -1,8 +1,16 @@ import subprocess import shutil import os +import argparse from pathlib import Path +parser = argparse.ArgumentParser() + +parser.add_argument( + "-y", "--yes", help="use assumed node bin directory.", action="store_true" +) + + def runcmd(cmd): if os.name == "nt": return subprocess.check_output(cmd, shell=True) @@ -17,12 +25,15 @@ try: except: node_bin = Path(out.decode('utf-8').rstrip()) -print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") -if input("[yY/nN]: ").lower() == "n": - node_bin = local_path.parent / 'node_modules' / '.bin' - print(f"this? \"{node_bin}\"") +args = parser.parse_args() + +if not args.yes: + print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") if input("[yY/nN]: ").lower() == "n": - node_bin = input("input bin directory: ") + node_bin = local_path.parent / 'node_modules' / '.bin' + print(f"this? \"{node_bin}\"") + if input("[yY/nN]: ").lower() == "n": + node_bin = input("input bin directory: ") for mjml in [f for f in local_path.iterdir() if f.is_file() and 'mjml' in f.suffix]: print(f'Compiling {mjml.name}') diff --git a/scss/compile.py b/scss/compile.py index fe634a3..88c02d1 100755 --- a/scss/compile.py +++ b/scss/compile.py @@ -3,8 +3,16 @@ import sass import subprocess import shutil import os +import argparse from pathlib import Path +parser = argparse.ArgumentParser() + +parser.add_argument( + "-y", "--yes", help="use assumed node bin directory.", action="store_true" +) + + def runcmd(cmd): if os.name == "nt": return subprocess.check_output(cmd, shell=True) @@ -19,12 +27,15 @@ try: except: node_bin = Path(out.decode('utf-8').rstrip()) -print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") -if input("[yY/nN]: ").lower() == "n": - node_bin = local_path.parent / 'node_modules' / '.bin' - print(f"this? \"{node_bin}\"") +args = parser.parse_args() + +if not args.yes: + print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") if input("[yY/nN]: ").lower() == "n": - node_bin = input("input bin directory: ") + node_bin = local_path.parent / 'node_modules' / '.bin' + print(f"this? \"{node_bin}\"") + if input("[yY/nN]: ").lower() == "n": + node_bin = input("input bin directory: ") for bsv in [d for d in local_path.iterdir() if 'bs' in d.name]: scss = bsv / f'{bsv.name}-jf.scss'