github.com/yourbase/yb@v0.7.1/cmd/yb/checkconfig.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/spf13/cobra"
     7  	"github.com/yourbase/yb"
     8  	"zombiezen.com/go/log"
     9  )
    10  
    11  type checkConfigCmd struct {
    12  	file string
    13  }
    14  
    15  func newCheckConfigCmd() *cobra.Command {
    16  	b := new(checkConfigCmd)
    17  	c := &cobra.Command{
    18  		Use:                   "checkconfig [-file FILE]",
    19  		Short:                 "Check the config file syntax",
    20  		Long:                  `Validate the local YourBase config file, .yourbase.yml by default.`,
    21  		Args:                  cobra.NoArgs,
    22  		DisableFlagsInUseLine: true,
    23  		SilenceErrors:         true,
    24  		SilenceUsage:          true,
    25  		RunE: func(cmd *cobra.Command, args []string) error {
    26  			return b.run(cmd.Context())
    27  		},
    28  	}
    29  	c.Flags().StringVar(&b.file, "file", yb.PackageConfigFilename, "YAML file to check")
    30  	return c
    31  }
    32  
    33  func (b *checkConfigCmd) run(ctx context.Context) error {
    34  	targetPackage, err := yb.LoadPackage(b.file)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	log.Infof(ctx, "Syntax for package '%s' is OK: your package is YourBase'd!", targetPackage.Name)
    40  	return nil
    41  }