github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/globals/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 globals 6 7 import ( 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/validate" 11 ) 12 13 func (opts *GlobalOptions) Validate() error { 14 if len(opts.File) > 0 { 15 if opts.IsApiMode() { 16 return validate.Usage("The {0} option is not available{1}.", "--file", " in api mode") 17 } 18 if !file.FileExists(opts.File) { 19 return validate.Usage("The {0} option ({1}) must {2}", "file", opts.File, "exist") 20 } 21 } 22 23 if len(opts.File) > 0 && !file.FileExists(opts.File) { 24 return validate.Usage("The {0} option ({1}) must {2}", "file", opts.File, "exist") 25 } 26 27 if len(opts.OutputFn) > 0 && opts.IsApiMode() { 28 return validate.Usage("The {0} option is not available{1}.", "--output", " in api mode") 29 } 30 31 // TODO: Can we re-enable this? It doesn't work in Sepolia under docker. Returns a really weird message. 32 // tmpPath := filepath.Join(config.PathToCache(opts.Chain), "tmp", "checkProvider.txt") 33 // if !file.FileExists(tmpPath) { 34 // if version, err := conn.GetClientVersion(opts.Chain); err != nil { 35 // logger.Fatal("Cannot connect with the node software.", version, err) 36 // } else { 37 // file.StringToAsciiFile(tmpPath, version) 38 // } 39 // } 40 41 err := validate.ValidateEnum("--fmt", opts.Format, "[json|txt|csv]") 42 if err != nil { 43 return err 44 } 45 46 // TODO: This hack is here to make test cases pass. It can be removed at some point 47 if opts.Format == "json" && len(opts.OutputFn) > 0 && opts.TestMode { 48 logger.Info("{ \"outputFilename\": \"--output_filename--\" }") 49 } 50 51 if opts.Cache && opts.Decache { 52 return validate.Usage("The {0} and {1} options are mutually exclusive.", "--cache", "--decache") 53 } 54 55 return nil 56 }