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

     1  package configPkg
     2  
     3  import (
     4  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
     5  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
     6  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
     7  )
     8  
     9  // HandlePaths handles the paths command for the command line. Returns error only as per cobra.
    10  func (opts *ConfigOptions) HandlePaths(rCtx *output.RenderCtx) error {
    11  	testMode := opts.Globals.TestMode
    12  
    13  	fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
    14  		root, cache, index := config.PathToRootConfig(),
    15  			config.PathToCache(opts.Globals.Chain),
    16  			config.PathToIndex(opts.Globals.Chain)
    17  		if testMode {
    18  			root, cache, index = "--path--", "--path--", "--path--"
    19  		}
    20  
    21  		paths := []types.CacheItem{
    22  			{
    23  				Path:          root,
    24  				CacheItemType: "configPath",
    25  			},
    26  			{
    27  				Path:          cache,
    28  				CacheItemType: "cachePath",
    29  			},
    30  			{
    31  				Path:          index,
    32  				CacheItemType: "indexPath",
    33  			},
    34  		}
    35  		for _, s := range paths {
    36  			modelChan <- &s
    37  		}
    38  	}
    39  
    40  	extraOpts := map[string]any{
    41  		"configPaths": true,
    42  	}
    43  	return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOptsWithExtra(extraOpts))
    44  }