Skip to content

Commit

Permalink
Merge pull request #80 from seqeralabs/bash_specific_constructs
Browse files Browse the repository at this point in the history
Support for bash specific syntax and sys.argv
  • Loading branch information
ejseqera authored Nov 7, 2023
2 parents 29f952c + c1d543b commit 78a8da7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions seqerakit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""
import argparse
import logging
import sys

from pathlib import Path
from seqerakit import seqeraplatform, helper, overwrite
Expand All @@ -28,7 +29,7 @@
logger = logging.getLogger(__name__)


def parse_args():
def parse_args(args=None):
parser = argparse.ArgumentParser()
parser.add_argument(
"-l",
Expand Down Expand Up @@ -61,7 +62,7 @@ def parse_args():
help="Additional arguments to pass to Seqera Platform"
" CLI enclosed in double quotes (e.g. '--cli=\"--insecure\"')",
)
return parser.parse_args()
return parser.parse_args(args if args is not None else sys.argv[1:])


class BlockParser:
Expand Down Expand Up @@ -122,8 +123,8 @@ def handle_block(self, block, args, destroy=False):
logger.error(f"Unrecognized resource block in YAML: {block}")


def main():
options = parse_args()
def main(args=None):
options = parse_args(args)
logging.basicConfig(level=options.log_level)

# Parse CLI arguments into a list
Expand All @@ -146,7 +147,6 @@ def main():
# Parse the YAML file(s) by blocks
# and get a dictionary of command line arguments
cmd_args_dict = helper.parse_all_yaml(options.yaml, destroy=options.delete)

for block, args_list in cmd_args_dict.items():
for args in args_list:
try:
Expand Down
5 changes: 4 additions & 1 deletion seqerakit/seqeraplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def _construct_command(self, cmd, *args, **kwargs):
# Checks environment variables to see that they are set accordingly
def _check_env_vars(self, command):
full_cmd_parts = []
shell_constructs = ["|", ">", "<", "$(", "&", "&&", "`"]
for arg in command:
if "$" in arg:
if any(construct in arg for construct in shell_constructs):
full_cmd_parts.append(arg)
elif "$" in arg:
for env_var in re.findall(r"\$\{?[\w]+\}?", arg):
if re.sub(r"[${}]", "", env_var) not in os.environ:
raise EnvironmentError(
Expand Down

0 comments on commit 78a8da7

Please sign in to comment.