Skip to content

Commit 2a1bac9

Browse files
committed
Add custom flags argument to get_main
1 parent 2769867 commit 2a1bac9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

biobb_common/generic/biobb_object.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def remove_tmp_files(self):
479479
fu.rm_file_list(self.tmp_files, self.out_log)
480480

481481
@classmethod
482-
def get_main(cls, launcher, description):
482+
def get_main(cls, launcher, description, custom_flags=None):
483483
"""Get command line execution of this building block. Please check the command line documentation."""
484484
def main():
485485
# Get the arguments and properties from the class docstring
@@ -491,6 +491,7 @@ def main():
491491
"-c", "--config", required=False,
492492
help="This file can be a YAML file, JSON file or JSON string",
493493
)
494+
required_args = parser.add_argument_group("required arguments")
494495
# Use the doc_arguments_dict to add arguments to the parser
495496
# If we have only one input or output argument, we can use shorthand flags -i/-o
496497
input_args = [arg for arg, arg_dict in doc_arguments_dict.items() if arg_dict.get("input_output", "").lower().startswith("input")]
@@ -499,15 +500,20 @@ def main():
499500
for argument, argument_dict in doc_arguments_dict.items():
500501
# Determine if we should add shorthand flags
501502
shorthand_flags = [f'--{argument}']
502-
if len(input_args) == 1 and argument in input_args:
503+
504+
# Check if custom flags are provided for this argument
505+
if custom_flags and argument in custom_flags:
506+
shorthand_flags.insert(0, custom_flags[argument])
507+
elif len(input_args) == 1 and argument in input_args:
503508
shorthand_flags.insert(0, '-i')
504509
elif len(output_args) == 1 and argument in output_args:
505510
shorthand_flags.insert(0, '-o')
506511

512+
help_str = argument_dict.get("description", "") + f". Accepted formats: {', '.join(argument_dict.get('formats', {}).keys())}."
507513
if argument_dict["optional"]:
508-
parser.add_argument(*shorthand_flags, required=False, help=argument_dict.get("description", ""))
514+
parser.add_argument(*shorthand_flags, required=False, help=help_str)
509515
else:
510-
parser.add_argument(*shorthand_flags, required=True, help=argument_dict.get("description", ""))
516+
required_args.add_argument(*shorthand_flags, required=True, help=help_str)
511517
# Parse the arguments from the command line
512518
args = parser.parse_args()
513519
args.config = args.config or "{}"

0 commit comments

Comments
 (0)