github.com/avenga/couper@v1.12.2/command/verify.go (about)

     1  package command
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/avenga/couper/cache"
     7  	"github.com/avenga/couper/config"
     8  	"github.com/avenga/couper/config/configload"
     9  	"github.com/avenga/couper/config/runtime"
    10  	"github.com/hashicorp/hcl/v2"
    11  	"github.com/sirupsen/logrus"
    12  )
    13  
    14  var _ Cmd = &Verify{}
    15  
    16  type Verify struct{}
    17  
    18  func NewVerify() *Verify {
    19  	return &Verify{}
    20  }
    21  
    22  func (v Verify) Execute(args Args, conf *config.Couper, logger *logrus.Entry) error {
    23  	cf, err := configload.LoadFiles(args, conf.Environment, logger)
    24  	if diags, ok := err.(hcl.Diagnostics); ok {
    25  		for _, diag := range diags {
    26  			logger.WithError(diag).Error()
    27  		}
    28  
    29  		return diags
    30  	} else if err != nil {
    31  		logger.WithError(err).Error()
    32  
    33  		return err
    34  	}
    35  
    36  	tmpStoreCh := make(chan struct{})
    37  	defer close(tmpStoreCh)
    38  
    39  	tmpMemStore := cache.New(logger, tmpStoreCh)
    40  
    41  	ctx, cancel := context.WithCancel(cf.Context)
    42  	cf.Context = ctx
    43  	defer cancel()
    44  
    45  	_, err = runtime.NewServerConfiguration(cf, logger, tmpMemStore)
    46  	if err != nil {
    47  		logger.WithError(err).Error()
    48  	}
    49  
    50  	return err
    51  }
    52  
    53  func (v Verify) Usage() {
    54  	println("Usage of verify:\n  verify [-f <file>]	[-d <dir>]	Verify the syntax of the given configuration file(s).")
    55  }