Skip to content

Commit

Permalink
🐛(ozi-new interactive): fix arg quoting
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Jun 28, 2024
1 parent e7949b8 commit 0b8d0fd
Showing 1 changed file with 34 additions and 46 deletions.
80 changes: 34 additions & 46 deletions ozi/new/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import curses
from itertools import chain
import os
import re
import sys
Expand Down Expand Up @@ -224,7 +225,7 @@ def license_( # noqa: C901
if license_ is None:
result, output, prefix = menu_loop(output, prefix)
if isinstance(result, list):
output += [f'--license="{_default}"'] if _default else []
output += ['--license', _default] if _default else []
return result, output, prefix
else:
if validate_message(license_ if license_ else '', LengthValidator())[0]:
Expand All @@ -239,10 +240,10 @@ def license_( # noqa: C901
{f'{Prefix().license}': f'{Prefix().license}{license_ if license_ else ""}'},
)
if license_:
output += [f'--license="{license_}"']
output += ['--license', license_]
else:
output += [f'--license="{_default}"'] if _default else []
output += [f'--license="{license_}"'] if license_ else []
output += ['--license', _default] if _default else []
output += ['--license', license_] if license_ else []
return license_, output, prefix

@staticmethod
Expand Down Expand Up @@ -290,7 +291,7 @@ def license_expression( # noqa: C901
ok_text='✔ Ok',
).run()
if license_id is None:
output += [f'--license-expression="{_default}"'] if _default else []
output += ['--license-expression', _default] if _default else []
result, output, prefix = menu_loop(output, prefix)
if isinstance(result, list):
return result, output, prefix
Expand All @@ -316,9 +317,9 @@ def license_expression( # noqa: C901
).run()
break
if _license_expression:
output += [f'--license-expression="{_license_expression}"']
output += ['--license-expression', _license_expression]
else:
output += [f'--license-expression="{_default}"'] if len(_default) > 0 else []
output += ['--license-expression', _default] if len(_default) > 0 else []
prefix.update(
{
'Extra: License-Expression ::': f'Extra: License-Expression :: {_license_expression if _license_expression else ""}', # pyright: ignore # noqa: B950, RUF100, E501
Expand Down Expand Up @@ -409,7 +410,7 @@ def requires_dist(
),
},
)
output += [f'--requires-dist="{requirement}"'] if requirement else []
output += ['--requires-dist', requirement] if requirement else []
case False:
if len(_requires_dist) != 0:
del_requirement = checkboxlist_dialog(
Expand All @@ -425,12 +426,9 @@ def requires_dist(
set(del_requirement),
),
)
output = list(
set(output).symmetric_difference(
{f'--requires-dist="{del_requirement}"'},
),
)
for req in del_requirement:
output.pop(output.index(req) - 1)
output.remove(req)
prefix.pop(f'Requires-Dist: {req}')
else:
message_dialog(
Expand Down Expand Up @@ -471,9 +469,9 @@ def readme_type(
cancel_text='← Back',
).run()
if readme_type is not None:
output += [f'--readme-type="{readme_type}"']
output += ['--readme-type', readme_type]
else:
output += [f'--readme-type="{_default}"'] if _default else []
output += ['--readme-type', _default] if _default else []
prefix.update(
(
{
Expand Down Expand Up @@ -508,9 +506,9 @@ def typing(
cancel_text='← Back',
).run()
if result is not None:
output += [f'--typing="{result}"']
output += ['--typing', result]
else:
output += [f'--typing="{_default}"'] if _default else []
output += ['--typing', _default] if _default else []
prefix.update(
(
{
Expand Down Expand Up @@ -781,7 +779,7 @@ def header_input( # noqa: C901
_default = ''
for n, i in enumerate(output):
if i.startswith(f'--{label.lower()}'):
_default = output.pop(n).replace(f'--{label.lower()}=', '').strip('"')
_default = output.pop(n+1)
header = input_dialog(
title='ozi-new interactive prompt',
text='\n'.join(args),
Expand All @@ -792,7 +790,7 @@ def header_input( # noqa: C901
ok_text='✔ Ok',
).run()
if header is None:
output += [f'--{label.lower()}="{_default}"'] if len(_default) > 0 else []
output += [f'--{label.lower()}', _default] if len(_default) > 0 else []
result, output, prefix = menu_loop(output, prefix)
return result, output, prefix
else:
Expand All @@ -802,17 +800,17 @@ def header_input( # noqa: C901
prefix.update({label: f'{label}: {header}'})
if split_on:
header = header.rstrip(split_on).split(split_on) # type: ignore
output += [f'--{label.lower()}="{i}"' for i in header]
output += chain.from_iterable([[f'--{label.lower()}', i] for i in header])
else:
output += [f'--{label.lower()}="{header}"']
output += [f'--{label.lower()}', header]
return True, output, prefix
message_dialog(
title='ozi-new interactive prompt',
text=f'Invalid input "{header}"\n{errmsg}\nPress ENTER to continue.',
style=_style,
ok_text='✔ Ok',
).run()
output += [f'--{label.lower()}="{_default}"'] if len(_default) > 0 else []
output += [f'--{label.lower()}', _default] if len(_default) > 0 else []
return None, output, prefix


Expand Down Expand Up @@ -933,10 +931,10 @@ def menu_loop(
'topic',
):
classifier = classifier_checkboxlist(x)
output += (
[f'--{x}="{c}"' for c in classifier]
output += chain.from_iterable(
[[f'--{x}', c] for c in classifier]
if classifier
else []
else [],
)
prefix.update(
(
Expand Down Expand Up @@ -1000,12 +998,9 @@ def menu_loop(
case x if x and x == 'copyright_head':
_default = None
for n, i in enumerate(output):
if i.startswith('--copyright-head'):
_default = (
output.pop(n)
.replace('--copyright-head=', '')
.strip('"')
)
if i == '--copyright-head':
_default = output.pop(n+1)
output.remove('--copyright-head')
_default = (
_default
if _default
Expand All @@ -1021,17 +1016,13 @@ def menu_loop(
).run()
if result != _default:
_P.copyright_head = result
output += [f'--copyright-head="{_P.copyright_head}"']
output += ['--copyright-head', _P.copyright_head]
case x if x and x == 'allow_file':
_default = None
for n, i in enumerate(output):
if i.startswith('--allow-file'):
_default = (
output.pop(n)
.replace('--allow-file=', '')
.strip('"')
.split(',')
)
if i == '--allow-file':
_default = output.pop(n+1).split(',')
output.remove('--allow-file')
_default = (
_default
if _default
Expand All @@ -1047,16 +1038,13 @@ def menu_loop(
).run()
if result != ','.join(_default) and result is not None:
_P.allow_file = [i.strip() for i in result.split(',')]
output += [f'--allow-file="{result}"']
output += ['--allow-file', result]
case x if x and x == 'ci_provider':
_default = None
for n, i in enumerate(output):
if i.startswith('--ci-provider'):
_default = (
output.pop(n)
.replace('--ci-provider=', '')
.strip('"')
)
_default = output.pop(n+1)
output.remove('--ci-provider')
_default = _default if _default else 'github'
result = radiolist_dialog(
title='ozi-new interactive prompt',
Expand All @@ -1069,7 +1057,7 @@ def menu_loop(
).run()
if result != _default and result is not None:
_P.ci_provider = result
output += [f'--ci-provider="{_P.ci_provider}"']
output += ['--ci-provider', _P.ci_provider]
case _:
break
case 1:
Expand Down

0 comments on commit 0b8d0fd

Please sign in to comment.