Skip to content

Commit

Permalink
polish miniwdl configure
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jan 13, 2021
1 parent 63b0f48 commit 9e53f9e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions WDL/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@ def fill_configure_subparser(subparsers):


def configure(cfg=None, show=False, force=False, **kwargs):
if not (sys.stdin.isatty() and sys.stdout.isatty()):
die("`miniwdl configure` is for interactive use")

from datetime import datetime
import bullet
from xdg import XDG_CONFIG_HOME

Expand All @@ -1521,19 +1525,21 @@ def configure(cfg=None, show=False, force=False, **kwargs):
if not cfg:
cfg = os.path.join(XDG_CONFIG_HOME, "miniwdl.cfg")

def yes(prompt):
return bullet.Bullet(prompt=prompt, choices=["No", "Yes"]).launch() == "Yes"

if os.path.exists(cfg):
assert force
logger.warn("Deleting existing configuration file at " + cfg)
logger.warn("Proceeding will overwrite existing configuration file at " + cfg)
sys.stderr.flush()
if not yes("OVERWRITE?"):
sys.exit(0)
os.unlink(cfg)
logger.notice("Generating configuration file at " + cfg)
sys.stderr.flush()

options = {}
try:

def yes(prompt):
return bullet.Bullet(prompt=prompt, choices=["No", "Yes"]).launch() == "Yes"

print(
textwrap.dedent(
"""
Expand Down Expand Up @@ -1601,12 +1607,16 @@ def yes(prompt):
print()
sys.stdout.flush()
with open(cfg, "w") as outfile:
print(
f"# miniwdl configure {miniwdl_version or '(version unknown)'} {datetime.utcnow()}Z",
file=outfile,
)
print(cfg_content, file=outfile)
logger.notice("Wrote configuration file " + cfg)
logger.notice("Edit the file manually to set advanced options available: ")
logger.notice(
" https://github.com/chanzuckerberg/miniwdl/blob/"
f"{miniwdl_version}/WDL/runtime/config_templates/default.cfg"
f"{miniwdl_version or 'main'}/WDL/runtime/config_templates/default.cfg"
)
logger.notice(
"Runtime environment variables may override configuration file options; see documentation:"
Expand Down

0 comments on commit 9e53f9e

Please sign in to comment.