bubble up an error code when something goes wrong with import/export

(cherry picked from commit babd6f0975)
This commit is contained in:
Sarabraj Singh
2022-06-10 14:48:36 -04:00
parent 5bd4aade0e
commit 05df2ebad2
2 changed files with 26 additions and 3 deletions

View File

@@ -144,6 +144,8 @@ class Import(CustomCommand):
client.authenticate()
client.v2.import_assets(data)
self._has_error = getattr(client.v2, '_has_error', False)
return {}
@@ -174,7 +176,11 @@ class Export(CustomCommand):
kwargs = {resource: getattr(parsed, resource, None) for resource in EXPORTABLE_RESOURCES}
client.authenticate()
return client.v2.export_assets(**kwargs)
data = client.v2.export_assets(**kwargs)
self._has_error = getattr(client.v2, '_has_error', False)
return data
def parse_resource(client, skip_deprecated=False):
@@ -183,6 +189,8 @@ def parse_resource(client, skip_deprecated=False):
metavar='resource',
)
_system_exit = 0
# check if the user is running a custom command
for command in CustomCommand.__subclasses__():
client.subparsers[command.name] = subparsers.add_parser(command.name, help=command.help_text)
@@ -210,6 +218,10 @@ def parse_resource(client, skip_deprecated=False):
parser = client.subparsers[resource]
command = CustomCommand.registry[resource]()
response = command.handle(client, parser)
if getattr(command, '_has_error', False):
_system_exit = 1
if response:
_filter = client.get_config('filter')
if resource == 'config' and client.get_config('format') == 'human':
@@ -221,7 +233,7 @@ def parse_resource(client, skip_deprecated=False):
connection = None
formatted = format_response(Page.from_json(response, connection=connection), fmt=client.get_config('format'), filter=_filter)
print(formatted)
raise SystemExit()
raise SystemExit(_system_exit)
else:
return resource