github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/interface.go (about)

     1  package compilers
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/solo-io/unik/pkg/types"
     6  	"strings"
     7  )
     8  
     9  type Compiler interface {
    10  	CompileRawImage(params types.CompileImageParams) (*types.RawImage, error)
    11  
    12  	// Usage describes how to prepare project to run it with UniK
    13  	// The returned text should describe what configuration files to
    14  	// prepare and how.
    15  	Usage() *CompilerUsage
    16  }
    17  
    18  type CompilerUsage struct {
    19  	// PrepareApplication section briefly describes how user should
    20  	// prepare her application PRIOR composing unikernel with UniK
    21  	PrepareApplication string
    22  
    23  	// ConfigurationFiles lists configuration files needed by UniK.
    24  	// It is a map filename:content_description.
    25  	ConfigurationFiles map[string]string
    26  
    27  	// Other is arbitrary content that will be printed at the end.
    28  	Other string
    29  }
    30  
    31  func (c *CompilerUsage) ToString() string {
    32  	prepApp := strings.TrimSpace(c.PrepareApplication)
    33  	other := strings.TrimSpace(c.Other)
    34  
    35  	configFiles := ""
    36  	for k := range c.ConfigurationFiles {
    37  		configFiles += fmt.Sprintf("------ %s ------\n", k)
    38  		configFiles += strings.TrimSpace(c.ConfigurationFiles[k])
    39  		configFiles += "\n\n"
    40  	}
    41  	configFiles = strings.TrimSpace(configFiles)
    42  
    43  	description := fmt.Sprintf(`
    44  HOW TO PREPARE APPLICATION	
    45  %s
    46  
    47  CONFIGURATION FILES
    48  %s
    49  `, prepApp, configFiles)
    50  
    51  	if other != "" {
    52  		description += fmt.Sprintf("\nOTHER\n%s", other)
    53  	}
    54  
    55  	return description
    56  }