Skip to content

Commit

Permalink
"ddev list" shows sites based on container, even if directory is remo…
Browse files Browse the repository at this point in the history
…ved: fix for #374 (#444)

* Add site status for directory removed

* In the case of a missing site directory, initalization can be done manually using .

* Remove erraneous InitFromMissingDirectory function and add some context to our changes using comments.

* Cast site to *LocalApp.

* Handle potential errors while casting using . Use better name for variable storing the casted value.

* Adjusted error message presented on failure to cast.

* Present value of site instead of siteStruct.

* Handle the case of a missing .ddev/config.yml file
  • Loading branch information
nmccrory committed Sep 12, 2017
1 parent 95e0157 commit d47345f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewConfig(AppRoot string, provider string) (*Config, error) {
// and it is up to the caller to determine if that's an issue.
err := c.Read()
if err != nil {
return c, err
return c, fmt.Errorf("Unable to read config.yaml, %v, err=%v", c.ConfigPath, err)
}

return c, err
Expand Down
13 changes: 13 additions & 0 deletions pkg/plugins/platform/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (l *LocalApp) GetType() string {
func (l *LocalApp) Init(basePath string) error {
config, err := ddevapp.NewConfig(basePath, "")
if err != nil {
// Save config to l.AppConfig so we can capture and display the site's status.
l.AppConfig = config
return err
}

Expand Down Expand Up @@ -266,6 +268,17 @@ func (l *LocalApp) SiteStatus() string {
var siteStatus string
services := map[string]string{"web": "", "db": ""}

if !fileutil.FileExists(l.AppRoot()) {
siteStatus := fmt.Sprintf("%s: %v", SiteDirMissing, l.AppRoot())
return siteStatus
}

_, err := CheckForConf(l.AppRoot())
if err != nil {
siteStatus := fmt.Sprintf("%s", SiteConfigMissing)
return siteStatus
}

for service := range services {
container, err := l.FindContainerByType(service)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/plugins/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const SiteRunning = "running"
// SiteNotFound defines the string used to denote a site where the containers were not found/do not exist.
const SiteNotFound = "not found"

// SiteDirMissing defines the string used to denote when a site is missing its application directory.
const SiteDirMissing = "app directory missing"

// SiteConfigMissing defines the string used to denote when a site is missing its .ddev/config.yml file.
const SiteConfigMissing = ".ddev/config.yml missing"

// SiteStopped defines the string used to denote when a site is in the stopped state.
const SiteStopped = "stopped"

Expand Down
17 changes: 14 additions & 3 deletions pkg/plugins/platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ func GetApps() map[string][]App {
}

err = site.Init(approot)
if err == nil {
apps[platformType] = append(apps[platformType], site)
if err != nil {
// Cast 'site' from type App to type LocalApp, so we can manually enter AppConfig values.
siteStruct, ok := site.(*LocalApp)
if !ok {
log.Fatalf("Failed to cast siteStruct(type App) to *LocalApp{}. site=%v", site)
}

siteStruct.AppConfig.Name = siteContainer.Labels["com.ddev.site-name"]
siteStruct.AppConfig.AppType = siteContainer.Labels["com.ddev.app-type"]
}
apps[platformType] = append(apps[platformType], site)
}
}
}
Expand All @@ -66,7 +74,6 @@ func RenderAppTable(platform string, apps []App) {
fmt.Println(table)
fmt.Println(PrintRouterStatus())
}

}

// CreateAppTable will create a new app table for describe and list output
Expand Down Expand Up @@ -97,6 +104,10 @@ func RenderAppRow(table *uitable.Table, site App) {
status = color.YellowString(status)
case strings.Contains(status, SiteNotFound):
status = color.RedString(status)
case strings.Contains(status, SiteDirMissing):
status = color.RedString(status)
case strings.Contains(status, SiteConfigMissing):
status = color.RedString(status)
default:
status = color.CyanString(status)
}
Expand Down

0 comments on commit d47345f

Please sign in to comment.