Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code tidy #544

Merged
merged 3 commits into from
Aug 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cf/api/authentication/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ var _ = Describe("AuthenticationRepository", func() {
})

Describe("refreshing the auth token", func() {
var refreshedToken string
var apiErr error

JustBeforeEach(func() {
refreshedToken, apiErr = auth.RefreshAuthToken()
_, apiErr = auth.RefreshAuthToken()
})

Context("when the refresh token has expired", func() {
Expand Down
10 changes: 0 additions & 10 deletions cf/commands/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ type ShowApp struct {
pluginCall bool
}

func NewShowApp(ui terminal.UI, config core_config.Reader, appSummaryRepo api.AppSummaryRepository, appInstancesRepo app_instances.AppInstancesRepository, appLogsNoaaRepo api.LogsNoaaRepository) (cmd *ShowApp) {
cmd = &ShowApp{}
cmd.ui = ui
cmd.config = config
cmd.appSummaryRepo = appSummaryRepo
cmd.appInstancesRepo = appInstancesRepo
cmd.appLogsNoaaRepo = appLogsNoaaRepo
return
}

func init() {
command_registry.Register(&ShowApp{})
}
Expand Down
6 changes: 3 additions & 3 deletions cf/commands/application/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ func hostNameForString(name string) string {
}

func (cmd *Push) findDomain(domainName *string) (domain models.DomainFields) {
domain, error := cmd.domainRepo.FirstOrDefault(cmd.config.OrganizationFields().Guid, domainName)
if error != nil {
cmd.ui.Failed(error.Error())
domain, err := cmd.domainRepo.FirstOrDefault(cmd.config.OrganizationFields().Guid, domainName)
if err != nil {
cmd.ui.Failed(err.Error())
}

return
Expand Down
54 changes: 2 additions & 52 deletions cf/commands/application/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/flags"
"github.com/cloudfoundry/loggregatorlib/logmessage"
"github.com/cloudfoundry/sonde-go/events"

"github.com/cloudfoundry/cli/cf"
"github.com/cloudfoundry/cli/cf/api"
Expand Down Expand Up @@ -116,52 +115,13 @@ func (cmd *Start) SetDependency(deps command_registry.Dependency, pluginCall boo
cmd.StartupTimeout = DefaultStartupTimeout
}

//set appDisplayer
appCommand := command_registry.Commands.FindCommand("app")
appCommand = appCommand.SetDependency(deps, false)
cmd.appDisplayer = appCommand.(ApplicationDisplayer)

return cmd
}

func NewStart(ui terminal.UI, config core_config.Reader, appDisplayer ApplicationDisplayer, appRepo applications.ApplicationRepository, appInstancesRepo app_instances.AppInstancesRepository, logRepo api.LogsNoaaRepository, oldLogsRepo api.OldLogsRepository) (cmd *Start) {
cmd = new(Start)
cmd.ui = ui
cmd.config = config
cmd.appDisplayer = appDisplayer
cmd.appRepo = appRepo
cmd.appInstancesRepo = appInstancesRepo
cmd.logRepo = logRepo
cmd.oldLogsRepo = oldLogsRepo
cmd.LogServerConnectionTimeout = 20 * time.Second

cmd.PingerThrottle = DefaultPingerThrottle

if os.Getenv("CF_STAGING_TIMEOUT") != "" {
duration, err := strconv.ParseInt(os.Getenv("CF_STAGING_TIMEOUT"), 10, 64)
if err != nil {
cmd.ui.Failed(T("invalid value for env var CF_STAGING_TIMEOUT\n{{.Err}}",
map[string]interface{}{"Err": err}))
}
cmd.StagingTimeout = time.Duration(duration) * time.Minute
} else {
cmd.StagingTimeout = DefaultStagingTimeout
}

if os.Getenv("CF_STARTUP_TIMEOUT") != "" {
duration, err := strconv.ParseInt(os.Getenv("CF_STARTUP_TIMEOUT"), 10, 64)
if err != nil {
cmd.ui.Failed(T("invalid value for env var CF_STARTUP_TIMEOUT\n{{.Err}}",
map[string]interface{}{"Err": err}))
}
cmd.StartupTimeout = time.Duration(duration) * time.Minute
} else {
cmd.StartupTimeout = DefaultStartupTimeout
}

return
}

func (cmd *Start) Execute(c flags.FlagContext) {
cmd.ApplicationStart(cmd.appReq.GetApplication(), cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name)
}
Expand Down Expand Up @@ -260,17 +220,7 @@ func (cmd *Start) SetStartTimeoutInSeconds(timeout int) {
cmd.StartupTimeout = time.Duration(timeout) * time.Second
}

func simpleOldLogMessageOutput(logMsg *logmessage.LogMessage) (msgText string) {
msgText = string(logMsg.GetMessage())
reg, err := regexp.Compile("[\n\r]+$")
if err != nil {
return
}
msgText = reg.ReplaceAllString(msgText, "")
return
}

func simpleLogMessageOutput(logMsg *events.LogMessage) (msgText string) {
func simpleLogMessageOutput(logMsg *logmessage.LogMessage) (msgText string) {
msgText = string(logMsg.GetMessage())
reg, err := regexp.Compile("[\n\r]+$")
if err != nil {
Expand All @@ -287,7 +237,7 @@ func (cmd *Start) tailStagingLogs(app models.Application, startChan, doneChan ch

err := cmd.oldLogsRepo.TailLogsFor(app.Guid, onConnect, func(msg *logmessage.LogMessage) {
if msg.GetSourceName() == LogMessageTypeStaging {
cmd.ui.Say(simpleOldLogMessageOutput(msg))
cmd.ui.Say(simpleLogMessageOutput(msg))
}
})
// err := cmd.logRepo.TailNoaaLogsFor(app.Guid, onConnect, func(msg *events.LogMessage) {
Expand Down
9 changes: 0 additions & 9 deletions cf/commands/application/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ func (cmd *Stop) SetDependency(deps command_registry.Dependency, pluginCall bool
return cmd
}

func NewStop(ui terminal.UI, config core_config.Reader, appRepo applications.ApplicationRepository) (cmd *Stop) {
cmd = new(Stop)
cmd.ui = ui
cmd.config = config
cmd.appRepo = appRepo

return
}

func (cmd *Stop) ApplicationStop(app models.Application, orgName, spaceName string) (updatedApp models.Application, err error) {
if app.State == "stopped" {
updatedApp = app
Expand Down
8 changes: 0 additions & 8 deletions cf/commands/domain/delete_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ func (cmd *DeleteDomain) SetDependency(deps command_registry.Dependency, pluginC
return cmd
}

func NewDeleteDomain(ui terminal.UI, config core_config.Reader, repo api.DomainRepository) (cmd *DeleteDomain) {
cmd = new(DeleteDomain)
cmd.ui = ui
cmd.config = config
cmd.domainRepo = repo
return
}

func (cmd *DeleteDomain) Execute(c flags.FlagContext) {
domainName := c.Args()[0]
domain, apiErr := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid)
Expand Down
8 changes: 0 additions & 8 deletions cf/commands/domain/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ func (cmd *ListDomains) SetDependency(deps command_registry.Dependency, pluginCa
return cmd
}

func NewListDomains(ui terminal.UI, config core_config.Reader, domainRepo api.DomainRepository) (cmd *ListDomains) {
cmd = new(ListDomains)
cmd.ui = ui
cmd.config = config
cmd.domainRepo = domainRepo
return
}

func (cmd *ListDomains) Execute(c flags.FlagContext) {
org := cmd.orgReq.GetOrganizationFields()

Expand Down
18 changes: 0 additions & 18 deletions cf/commands/organization/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ import (
. "github.com/onsi/gomega"
)

func callShowOrg(args []string, requirementsFactory *testreq.FakeReqFactory) (ui *testterm.FakeUI) {
ui = new(testterm.FakeUI)

token := core_config.TokenInfo{Username: "my-user"}

spaceFields := models.SpaceFields{}
spaceFields.Name = "my-space"

orgFields := models.OrganizationFields{}
orgFields.Name = "my-org"

configRepo := testconfig.NewRepositoryWithAccessToken(token)
configRepo.SetSpaceFields(spaceFields)
configRepo.SetOrganizationFields(orgFields)

return
}

var _ = Describe("org command", func() {
var (
ui *testterm.FakeUI
Expand Down
7 changes: 0 additions & 7 deletions cf/commands/plugin_repo/repo_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ func (cmd RepoPlugins) printErrors(repoError []string) {
}
}

func getListEndpoint(url string) string {
if strings.HasSuffix(url, "/") {
return url + "list"
}
return url + "/list"
}

func (cmd RepoPlugins) findRepoIndex(repoName string) int {
repos := cmd.config.PluginRepos()
for i, repo := range repos {
Expand Down
8 changes: 0 additions & 8 deletions cf/commands/service/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ func (cmd *MarketplaceServices) SetDependency(deps command_registry.Dependency,
return cmd
}

func NewMarketplaceServices(ui terminal.UI, config core_config.Reader, serviceBuilder service_builder.ServiceBuilder) MarketplaceServices {
return MarketplaceServices{
ui: ui,
config: config,
serviceBuilder: serviceBuilder,
}
}

func (cmd *MarketplaceServices) Execute(c flags.FlagContext) {
serviceName := c.String("s")

Expand Down
12 changes: 0 additions & 12 deletions cf/commands/space/create_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ func (cmd *CreateSpace) SetDependency(deps command_registry.Dependency, pluginCa
return cmd
}

func NewCreateSpace(ui terminal.UI, config core_config.Reader, spaceRoleSetter user.SpaceRoleSetter, spaceRepo spaces.SpaceRepository, orgRepo organizations.OrganizationRepository, userRepo api.UserRepository, spaceQuotaRepo space_quotas.SpaceQuotaRepository) (cmd CreateSpace) {
cmd.ui = ui
cmd.config = config
cmd.spaceRepo = spaceRepo
cmd.orgRepo = orgRepo
cmd.userRepo = userRepo
cmd.spaceQuotaRepo = spaceQuotaRepo

cmd.spaceRoleSetter = spaceRoleSetter
return
}

func (cmd *CreateSpace) Execute(c flags.FlagContext) {
spaceName := c.Args()[0]
orgName := c.String("o")
Expand Down
8 changes: 0 additions & 8 deletions cf/commands/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ func init() {
command_registry.Register(&ShowSpace{})
}

func NewShowSpace(ui terminal.UI, config core_config.Reader, quotaRepo space_quotas.SpaceQuotaRepository) (cmd *ShowSpace) {
cmd = new(ShowSpace)
cmd.ui = ui
cmd.config = config
cmd.quotaRepo = quotaRepo
return
}

func (cmd *ShowSpace) MetaData() command_registry.CommandMetadata {
fs := make(map[string]flags.FlagSet)
fs["guid"] = &cliFlags.BoolFlag{Name: "guid", Usage: T("Retrieve and display the given space's guid. All other output for the space is suppressed.")}
Expand Down
7 changes: 0 additions & 7 deletions cf/commands/space/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ type ListSpaces struct {
pluginCall bool
}

func NewListSpaces(ui terminal.UI, config core_config.Reader, spaceRepo spaces.SpaceRepository) (cmd ListSpaces) {
cmd.ui = ui
cmd.config = config
cmd.spaceRepo = spaceRepo
return
}

func init() {
command_registry.Register(&ListSpaces{})
}
Expand Down
8 changes: 0 additions & 8 deletions cf/commands/user/org_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ func init() {
command_registry.Register(&OrgUsers{})
}

func NewOrgUsers(ui terminal.UI, config core_config.Reader, userRepo api.UserRepository) (cmd *OrgUsers) {
cmd = &OrgUsers{}
cmd.ui = ui
cmd.config = config
cmd.userRepo = userRepo
return
}

func (cmd *OrgUsers) MetaData() command_registry.CommandMetadata {
fs := make(map[string]flags.FlagSet)
fs["a"] = &cliFlags.BoolFlag{Name: "a", Usage: T("List all users in the org")}
Expand Down
9 changes: 0 additions & 9 deletions cf/commands/user/space_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ func init() {
command_registry.Register(&SpaceUsers{})
}

func NewSpaceUsers(ui terminal.UI, config core_config.Reader, spaceRepo spaces.SpaceRepository, userRepo api.UserRepository) (cmd *SpaceUsers) {
cmd = &SpaceUsers{}
cmd.ui = ui
cmd.config = config
cmd.spaceRepo = spaceRepo
cmd.userRepo = userRepo
return
}

func (cmd *SpaceUsers) MetaData() command_registry.CommandMetadata {
return command_registry.CommandMetadata{
Name: "space-users",
Expand Down
6 changes: 0 additions & 6 deletions cf/models/environment_variable.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package models

func NewEnvironmentVariable(name string, value string) (e EnvironmentVariable) {
e.Name = name
e.Value = value
return
}

type EnvironmentVariable struct {
Name string
Value string
Expand Down
7 changes: 0 additions & 7 deletions cf/models/feature_flag.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package models

func NewFeatureFlag(name string, enabled bool, errorMessage string) (f FeatureFlag) {
f.Name = name
f.Enabled = enabled
f.ErrorMessage = errorMessage
return
}

type FeatureFlag struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Expand Down
10 changes: 0 additions & 10 deletions cf/models/space_quota.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package models

func NewSpaceQuota(name string, memory int64, routes int, services int, nonbasicservices bool, orgGuid string) (q SpaceQuota) {
q.Name = name
q.MemoryLimit = memory
q.RoutesLimit = routes
q.ServicesLimit = services
q.NonBasicServicesAllowed = nonbasicservices
q.OrgGuid = orgGuid
return
}

type SpaceQuota struct {
Guid string `json:"guid,omitempty"`
Name string `json:"name"`
Expand Down