github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/export/handle_decache.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 exportPkg
     6  
     7  import (
     8  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/monitor"
     9  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
    11  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/usage"
    12  )
    13  
    14  // HandleDecache handles the command chifra monitors --decache
    15  func (opts *ExportOptions) HandleDecache(rCtx *output.RenderCtx, monitorArray []monitor.Monitor) error {
    16  	fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
    17  		doIt := true
    18  		for _, mon := range monitorArray {
    19  			if doIt && !opts.Globals.IsApiMode() && !usage.QueryUser(mon.GetRemoveWarning(), "Not decaching") {
    20  				continue
    21  			}
    22  			doIt = false
    23  			showProgress := opts.Globals.ShowProgressNotTesting()
    24  			if result, err := mon.Decache(opts.Conn, showProgress); err != nil {
    25  				errorChan <- err
    26  				continue
    27  			} else {
    28  				modelChan <- &types.Message{
    29  					Msg: result,
    30  				}
    31  			}
    32  		}
    33  	}
    34  	opts.Globals.NoHeader = true
    35  	return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts())
    36  }