Skip to content

Commit

Permalink
fix: fix duplicate name bug
Browse files Browse the repository at this point in the history
Re #123
  • Loading branch information
ejseqera committed Mar 18, 2024
1 parent bc32a9b commit 72e2838
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
10 changes: 6 additions & 4 deletions seqerakit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, sp, list_for_add_method):
# Create an instance of Overwrite class
self.overwrite_method = overwrite.Overwrite(self.sp)

def handle_block(self, block, args, destroy=False):
def handle_block(self, block, args, destroy=False, dryrun=False):
# Check if delete is set to True, and call delete handler
if destroy:
logging.debug(" The '--delete' flag has been specified.\n")
Expand All @@ -127,12 +127,12 @@ def handle_block(self, block, args, destroy=False):

# Check if overwrite is set to True, and call overwrite handler
overwrite_option = args.get("overwrite", False)
if overwrite_option:
if overwrite_option and dryrun is False:
logging.debug(f" Overwrite is set to 'True' for {block}\n")
self.overwrite_method.handle_overwrite(
block, args["cmd_args"], overwrite_option
)
else:
elif dryrun is False:
self.overwrite_method.handle_overwrite(block, args["cmd_args"])

if block in self.list_for_add_method:
Expand Down Expand Up @@ -184,7 +184,9 @@ def main(args=None):
for args in args_list:
try:
# Run the 'tw' methods for each block
block_manager.handle_block(block, args, destroy=options.delete)
block_manager.handle_block(
block, args, destroy=options.delete, dryrun=options.dryrun
)
except (ResourceExistsError, ResourceCreationError) as e:
logging.error(e)
sys.exit(1)
Expand Down
21 changes: 15 additions & 6 deletions seqerakit/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,19 @@ def handle_pipelines(sp, args):

def find_name(cmd_args):
"""
Find and return the value associated with --name in the cmd_args list.
Find and return the value associated with --name in cmd_args, where cmd_args
can be a list, a tuple of lists, or nested lists/tuples.
"""
args_list = cmd_args.get("cmd_args", [])
for i in range(len(args_list) - 1):
if args_list[i] == "--name":
return args_list[i + 1]
return None

def search(args):
it = iter(args)
for arg in it:
if arg == "--name":
return next(it, None)
elif isinstance(arg, (list, tuple)):
result = search(arg)
if result is not None:
return result
return None

return search(cmd_args.get("cmd_args", []))

0 comments on commit 72e2838

Please sign in to comment.