github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/globals/output.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/logger" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 12 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" 13 ) 14 15 func (opts *GlobalOptions) OutputOpts() output.OutputOptions { 16 extraOpts := map[string]any{ 17 "ether": opts.Ether, 18 "testMode": opts.TestMode, 19 } 20 if opts.ShouldLoadNames(extraOpts["loadNames"] == true) { 21 parts := types.Custom | types.Prefund | types.Regular 22 if opts.TestMode { 23 parts |= types.Testing 24 } 25 if namesMap, err := names.LoadNamesMap(opts.Chain, parts, nil); err == nil { 26 extraOpts["namesMap"] = namesMap 27 } 28 } 29 30 return output.OutputOptions{ 31 Writer: opts.Writer, 32 Chain: opts.Chain, 33 TestMode: opts.TestMode, 34 NoHeader: opts.NoHeader, 35 Verbose: opts.Verbose, 36 Format: opts.Format, 37 OutputFn: opts.OutputFn, 38 Append: opts.Append, 39 JsonIndent: " ", 40 Extra: extraOpts, 41 } 42 } 43 44 func (opts *GlobalOptions) OutputOptsWithExtra(extraOpts map[string]any) output.OutputOptions { 45 if extraOpts != nil { 46 extraOpts["ether"] = opts.Ether 47 extraOpts["testMode"] = opts.TestMode 48 if opts.ShouldLoadNames(extraOpts["loadNames"] == true) { 49 parts := types.Custom | types.Prefund | types.Regular 50 if opts.TestMode { 51 parts |= types.Testing 52 } 53 if namesMap, err := names.LoadNamesMap(opts.Chain, parts, nil); err == nil { 54 extraOpts["namesMap"] = namesMap 55 } 56 } 57 } 58 59 return output.OutputOptions{ 60 Writer: opts.Writer, 61 Chain: opts.Chain, 62 TestMode: opts.TestMode, 63 NoHeader: opts.NoHeader, 64 Verbose: opts.Verbose, 65 Format: opts.Format, 66 OutputFn: opts.OutputFn, 67 Append: opts.Append, 68 JsonIndent: " ", 69 Extra: extraOpts, 70 } 71 } 72 73 func (opts *GlobalOptions) ShowProgress() bool { 74 if opts.TestMode || utils.IsFuzzing() { 75 return false 76 } 77 return len(opts.OutputFn) > 0 || !logger.IsTerminal() 78 } 79 80 func (opts *GlobalOptions) ShowProgressNotTesting() bool { 81 return !opts.TestMode && !utils.IsFuzzing() 82 }