func NewDependency(writer io.Writer, logger trace.Printer, envDialTimeout string) Dependency { deps := Dependency{} deps.TeePrinter = terminal.NewTeePrinter(writer) deps.UI = terminal.NewUI(os.Stdin, writer, deps.TeePrinter, logger) errorHandler := func(err error) { if err != nil { deps.UI.Failed(fmt.Sprintf("Config error: %s", err)) } } configPath, err := confighelpers.DefaultFilePath() if err != nil { errorHandler(err) } deps.Config = coreconfig.NewRepositoryFromFilepath(configPath, errorHandler) deps.ManifestRepo = manifest.NewDiskRepository() deps.AppManifest = manifest.NewGenerator() pluginPath := filepath.Join(confighelpers.PluginRepoDir(), ".cf", "plugins") deps.PluginConfig = pluginconfig.NewPluginConfig( errorHandler, configuration.NewDiskPersistor(filepath.Join(pluginPath, "config.json")), pluginPath, ) terminal.UserAskedForColors = deps.Config.ColorEnabled() terminal.InitColorSupport() deps.Gateways = map[string]net.Gateway{ "cloud-controller": net.NewCloudControllerGateway(deps.Config, time.Now, deps.UI, logger, envDialTimeout), "uaa": net.NewUAAGateway(deps.Config, deps.UI, logger, envDialTimeout), "routing-api": net.NewRoutingAPIGateway(deps.Config, time.Now, deps.UI, logger, envDialTimeout), } deps.RepoLocator = api.NewRepositoryLocator(deps.Config, deps.Gateways, logger) deps.PluginModels = &PluginModels{Application: nil} deps.PlanBuilder = planbuilder.NewBuilder( deps.RepoLocator.GetServicePlanRepository(), deps.RepoLocator.GetServicePlanVisibilityRepository(), deps.RepoLocator.GetOrganizationRepository(), ) deps.ServiceBuilder = servicebuilder.NewBuilder( deps.RepoLocator.GetServiceRepository(), deps.PlanBuilder, ) deps.BrokerBuilder = brokerbuilder.NewBuilder( deps.RepoLocator.GetServiceBrokerRepository(), deps.ServiceBuilder, ) deps.PluginRepo = pluginrepo.NewPluginRepo() deps.ServiceHandler = actors.NewServiceHandler( deps.RepoLocator.GetOrganizationRepository(), deps.BrokerBuilder, deps.ServiceBuilder, ) deps.ServicePlanHandler = actors.NewServicePlanHandler( deps.RepoLocator.GetServicePlanRepository(), deps.RepoLocator.GetServicePlanVisibilityRepository(), deps.RepoLocator.GetOrganizationRepository(), deps.PlanBuilder, deps.ServiceBuilder, ) deps.WordGenerator = generator.NewWordGenerator() deps.AppZipper = appfiles.ApplicationZipper{} deps.AppFiles = appfiles.ApplicationFiles{} deps.RouteActor = actors.NewRouteActor(deps.UI, deps.RepoLocator.GetRouteRepository(), deps.RepoLocator.GetDomainRepository()) deps.PushActor = actors.NewPushActor(deps.RepoLocator.GetApplicationBitsRepository(), deps.AppZipper, deps.AppFiles, deps.RouteActor) deps.ChecksumUtil = utils.NewSha1Checksum("") deps.Logger = logger return deps }
func (cmd *Plugins) Execute(c flags.FlagContext) error { var version string cmd.ui.Say(T("Listing Installed Plugins...")) plugins := cmd.config.Plugins() var table *terminal.UITable if c.Bool("checksum") { cmd.ui.Say(T("Computing sha1 for installed plugins, this may take a while ...")) table = cmd.ui.Table([]string{T("Plugin Name"), T("Version"), T("Command Name"), "sha1", T("Command Help")}) } else { table = cmd.ui.Table([]string{T("Plugin Name"), T("Version"), T("Command Name"), T("Command Help")}) } var sortedPluginNames sortutils.Alphabetic for k := range plugins { sortedPluginNames = append(sortedPluginNames, k) } sort.Sort(sortedPluginNames) for _, pluginName := range sortedPluginNames { metadata := plugins[pluginName] if metadata.Version.Major == 0 && metadata.Version.Minor == 0 && metadata.Version.Build == 0 { version = "N/A" } else { version = fmt.Sprintf("%d.%d.%d", metadata.Version.Major, metadata.Version.Minor, metadata.Version.Build) } for _, command := range metadata.Commands { args := []string{pluginName, version} if command.Alias != "" { args = append(args, command.Name+", "+command.Alias) } else { args = append(args, command.Name) } if c.Bool("checksum") { checksum := utils.NewSha1Checksum(metadata.Location) sha1, err := checksum.ComputeFileSha1() if err != nil { args = append(args, "n/a") } else { args = append(args, fmt.Sprintf("%x", sha1)) } } args = append(args, command.HelpText) table.Add(args...) } } cmd.ui.Ok() cmd.ui.Say("") err := table.Print() if err != nil { return err } return nil }