github.com/niteshexa/cloudfoundry_cli@v7.1.0+incompatible/command/v7/delete_isolation_segment_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/command/flag"
     6  )
     7  
     8  type DeleteIsolationSegmentCommand struct {
     9  	BaseCommand
    10  
    11  	RequiredArgs    flag.IsolationSegmentName `positional-args:"yes"`
    12  	Force           bool                      `short:"f" description:"Force deletion without confirmation"`
    13  	usage           interface{}               `usage:"CF_NAME delete-isolation-segment SEGMENT_NAME"`
    14  	relatedCommands interface{}               `related_commands:"disable-org-isolation, isolation-segments"`
    15  }
    16  
    17  func (cmd DeleteIsolationSegmentCommand) Execute(args []string) error {
    18  	err := cmd.SharedActor.CheckTarget(false, false)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	if !cmd.Force {
    24  		deleteSegment, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the isolation segment {{.IsolationSegmentName}}?", map[string]interface{}{
    25  			"IsolationSegmentName": cmd.RequiredArgs.IsolationSegmentName,
    26  		})
    27  
    28  		if promptErr != nil {
    29  			return promptErr
    30  		}
    31  
    32  		if !deleteSegment {
    33  			cmd.UI.DisplayText("Delete cancelled")
    34  			return nil
    35  		}
    36  	}
    37  
    38  	user, err := cmd.Config.CurrentUser()
    39  	if err != nil {
    40  		return err
    41  	}
    42  
    43  	cmd.UI.DisplayTextWithFlavor("Deleting isolation segment {{.SegmentName}} as {{.CurrentUser}}...", map[string]interface{}{
    44  		"SegmentName": cmd.RequiredArgs.IsolationSegmentName,
    45  		"CurrentUser": user.Name,
    46  	})
    47  
    48  	warnings, err := cmd.Actor.DeleteIsolationSegmentByName(cmd.RequiredArgs.IsolationSegmentName)
    49  	cmd.UI.DisplayWarnings(warnings)
    50  	if _, ok := err.(actionerror.IsolationSegmentNotFoundError); ok {
    51  		cmd.UI.DisplayWarning("Isolation segment {{.IsolationSegmentName}} does not exist.", map[string]interface{}{
    52  			"IsolationSegmentName": cmd.RequiredArgs.IsolationSegmentName,
    53  		})
    54  	} else if err != nil {
    55  		return err
    56  	}
    57  
    58  	cmd.UI.DisplayOK()
    59  
    60  	return nil
    61  }