github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/v3_apply_manifest_command.go (about)

     1  package v6
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/sharedaction"
     5  	"code.cloudfoundry.org/cli/actor/v3action"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     7  	"code.cloudfoundry.org/cli/command"
     8  	"code.cloudfoundry.org/cli/command/flag"
     9  	"code.cloudfoundry.org/cli/command/v6/shared"
    10  	"code.cloudfoundry.org/cli/util/manifestparser"
    11  )
    12  
    13  //go:generate counterfeiter . ManifestParser
    14  
    15  type ManifestParser interface {
    16  	v3action.ManifestParser
    17  	Parse(manifestPath string) error
    18  }
    19  
    20  //go:generate counterfeiter . V3ApplyManifestActor
    21  
    22  type V3ApplyManifestActor interface {
    23  	CloudControllerAPIVersion() string
    24  	ApplyApplicationManifest(parser v3action.ManifestParser, spaceGUID string) (v3action.Warnings, error)
    25  }
    26  
    27  type V3ApplyManifestCommand struct {
    28  	PathToManifest flag.PathWithExistenceCheck `short:"f" description:"Path to app manifest" required:"true"`
    29  	usage          interface{}                 `usage:"CF_NAME v3-apply-manifest -f APP_MANIFEST_PATH"`
    30  
    31  	UI          command.UI
    32  	Config      command.Config
    33  	SharedActor command.SharedActor
    34  	Actor       V3ApplyManifestActor
    35  	Parser      ManifestParser
    36  }
    37  
    38  func (cmd *V3ApplyManifestCommand) Setup(config command.Config, ui command.UI) error {
    39  	cmd.UI = ui
    40  	cmd.Config = config
    41  	cmd.SharedActor = sharedaction.NewActor(config)
    42  
    43  	ccClient, _, err := shared.NewV3BasedClients(config, ui, true, "")
    44  	if err != nil {
    45  		return err
    46  	}
    47  	cmd.Actor = v3action.NewActor(ccClient, config, nil, nil)
    48  	cmd.Parser = manifestparser.NewParser()
    49  
    50  	return nil
    51  }
    52  
    53  func (cmd V3ApplyManifestCommand) Execute(args []string) error {
    54  	pathToManifest := string(cmd.PathToManifest)
    55  
    56  	cmd.UI.DisplayWarning(command.ExperimentalWarning)
    57  
    58  	err := command.MinimumCCAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionApplicationFlowV3)
    59  	if err != nil {
    60  		return err
    61  	}
    62  
    63  	err = cmd.SharedActor.CheckTarget(true, true)
    64  	if err != nil {
    65  		return err
    66  	}
    67  
    68  	user, err := cmd.Config.CurrentUser()
    69  	if err != nil {
    70  		return err
    71  	}
    72  
    73  	cmd.UI.DisplayTextWithFlavor("Applying manifest {{.ManifestPath}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
    74  		"ManifestPath": pathToManifest,
    75  		"OrgName":      cmd.Config.TargetedOrganization().Name,
    76  		"SpaceName":    cmd.Config.TargetedSpace().Name,
    77  		"Username":     user.Name,
    78  	})
    79  
    80  	err = cmd.Parser.Parse(pathToManifest)
    81  	if err != nil {
    82  		return err
    83  	}
    84  
    85  	warnings, err := cmd.Actor.ApplyApplicationManifest(cmd.Parser, cmd.Config.TargetedSpace().GUID)
    86  	cmd.UI.DisplayWarnings(warnings)
    87  	if err != nil {
    88  		return err
    89  	}
    90  
    91  	cmd.UI.DisplayOK()
    92  
    93  	return nil
    94  }