github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/config/validate.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package configPkg
     6  
     7  import (
     8  	"os"
     9  
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
    11  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate"
    12  )
    13  
    14  func (opts *ConfigOptions) validateConfig() error {
    15  	chain := opts.Globals.Chain
    16  
    17  	opts.testLog()
    18  
    19  	if opts.BadFlag != nil {
    20  		return opts.BadFlag
    21  	}
    22  
    23  	if !config.IsChainConfigured(chain) {
    24  		return validate.Usage("chain {0} is not properly configured.", chain)
    25  	}
    26  
    27  	if opts.Paths {
    28  		if len(opts.Mode) > 0 && opts.Mode != "<empty>" {
    29  			return validate.Usage("You must supply either {0} or {1}.", "a mode", "--paths")
    30  		}
    31  	} else {
    32  		if err := validate.ValidateEnum("modes", opts.Mode, "[show|edit]"); err != nil {
    33  			return err
    34  		}
    35  	}
    36  
    37  	if !opts.Globals.TestMode && opts.Mode == "edit" && os.Getenv("EDITOR") == "" {
    38  		return validate.Usage("You must set the EDITOR environment variable to use the 'edit' mode.")
    39  	}
    40  
    41  	// if len(opts.Mode) == 0 || !opts.Paths {
    42  	// 	return validate.Usage("You must supply either {0} or {1}.", "a mode", "--paths")
    43  	// }
    44  
    45  	return opts.Globals.Validate()
    46  }