| 380 | |
| 381 | |
| 382 | class PackRemoveCommand(PackAsyncCommand): |
| 383 | def __init__(self, resource, *args, **kwargs): |
| 384 | super(PackRemoveCommand, self).__init__( |
| 385 | resource, |
| 386 | "remove", |
| 387 | "Remove %s." % resource.get_plural_display_name().lower(), |
| 388 | *args, |
| 389 | **kwargs, |
| 390 | ) |
| 391 | |
| 392 | self.parser.add_argument( |
| 393 | "packs", |
| 394 | nargs="+", |
| 395 | metavar="pack", |
| 396 | help="Name of the %s to remove." |
| 397 | % resource.get_plural_display_name().lower(), |
| 398 | ) |
| 399 | |
| 400 | def run(self, args, **kwargs): |
| 401 | return self.manager.remove(args.packs, **kwargs) |
| 402 | |
| 403 | @add_auth_token_to_kwargs_from_cli |
| 404 | def run_and_print(self, args, **kwargs): |
| 405 | all_pack_instances = self.app.client.managers["Pack"].get_all(**kwargs) |
| 406 | |
| 407 | super(PackRemoveCommand, self).run_and_print(args, **kwargs) |
| 408 | |
| 409 | packs = args.packs |
| 410 | |
| 411 | if len(packs) == 1: |
| 412 | pack_instance = self.app.client.managers["Pack"].get_by_ref_or_id( |
| 413 | packs[0], **kwargs |
| 414 | ) |
| 415 | |
| 416 | if pack_instance: |
| 417 | raise OperationFailureException( |
| 418 | "Pack %s has not been removed properly" % packs[0] |
| 419 | ) |
| 420 | |
| 421 | removed_pack_instance = next( |
| 422 | (pack for pack in all_pack_instances if pack.name == packs[0]), None |
| 423 | ) |
| 424 | |
| 425 | self.print_output( |
| 426 | removed_pack_instance, |
| 427 | table.PropertyValueTable, |
| 428 | attributes=args.attr, |
| 429 | json=args.json, |
| 430 | yaml=args.yaml, |
| 431 | attribute_display_order=self.attribute_display_order, |
| 432 | ) |
| 433 | else: |
| 434 | remaining_pack_instances = self.app.client.managers["Pack"].get_all( |
| 435 | **kwargs |
| 436 | ) |
| 437 | pack_instances = [] |
| 438 | |
| 439 | for pack in all_pack_instances: |