github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/cli/command/context.go (about)

     1  package command
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/docker/cli/cli/context/store"
     7  )
     8  
     9  // DockerContext is a typed representation of what we put in Context metadata
    10  type DockerContext struct {
    11  	Description       string       `json:",omitempty"`
    12  	StackOrchestrator Orchestrator `json:",omitempty"`
    13  }
    14  
    15  // GetDockerContext extracts metadata from stored context metadata
    16  func GetDockerContext(storeMetadata store.Metadata) (DockerContext, error) {
    17  	if storeMetadata.Metadata == nil {
    18  		// can happen if we save endpoints before assigning a context metadata
    19  		// it is totally valid, and we should return a default initialized value
    20  		return DockerContext{}, nil
    21  	}
    22  	res, ok := storeMetadata.Metadata.(DockerContext)
    23  	if !ok {
    24  		return DockerContext{}, errors.New("context metadata is not a valid DockerContext")
    25  	}
    26  	return res, nil
    27  }