Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit d81713e

Browse files
author
Anton Khodak
committed
Fix #26: add specifying filename in case of one file and separate verbose output
1 parent 3449645 commit d81713e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

argparse/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,20 @@ def parse_args_cwl(self, *args, **kwargs):
120120
tool.description += argp.epilog
121121

122122
data = tool.export()
123-
filename = '{0}.cwl'.format(tool.name.replace('.py',''))
124-
filename = re.sub('\s+', '-', filename)
123+
# if there is more than one file, ignore specified filename
124+
if 'filename' in kwargs and len(tools)==1:
125+
filename = kwargs['filename']
126+
else:
127+
filename = '{0}.cwl'.format(tool.name.replace('.py',''))
128+
filename = re.sub('\s+', '-', filename)
125129
directory = kwargs.get('directory', '')
126130
if directory and directory[-1] != '/':
127131
directory += '/'
128132
filename = directory + filename
129133
with open(filename, 'w') as f:
130134
f.write(data)
131-
print(data)
135+
if 'verbose' in kwargs:
136+
print(data)
132137
else:
133138
continue
134139
sys.exit(0)

cmdline2cwl/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def __init__(self):
6060
help='Command for running your tool(s), without arguments')
6161
arg2cwl_parser.add_argument('-d', '--directory',
6262
help='Directory to store CWL tool descriptions')
63+
arg2cwl_parser.add_argument('-f', '--filename',
64+
help='Name of the generated file (if single). Default - the name of the running command')
65+
arg2cwl_parser.add_argument('-v', '--verbose', action='store_true',
66+
help='Print generated file(s) to stdout')
6367
arg2cwl_parser.add_argument('-b', '--basecommand',
6468
help='Command that appears in `basecommand` field in CWL tool '
6569
'instead of the default one')
@@ -92,13 +96,15 @@ def process_arguments(self):
9296
else:
9397
formcommand += kwargs['command']
9498

95-
attrs = ['directory', 'output_section', 'basecommand', 'generate_outputs']
99+
attrs = ['directory', 'filename', 'output_section', 'basecommand', 'generate_outputs', 'verbose']
96100
for arg in attrs:
97101
if getattr(self.args, arg):
98102
kwargs[arg] = getattr(self.args, arg)
99103

100104
if kwargs.get('output_section', ''):
101105
formcommand += ' -o FILENAME'
106+
if kwargs.get('filename', ''):
107+
formcommand += ' -f FILENAME'
102108
if kwargs.get('basecommand', ''):
103109
formcommand += ' -b {0}'.format(kwargs['basecommand'])
104110
if kwargs.get('generate_outputs', ''):

0 commit comments

Comments
 (0)