github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/abis/handle_count.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 abisPkg 6 7 import ( 8 "path/filepath" 9 "strings" 10 11 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 12 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 13 ) 14 15 // HandleCount handles the chifra abis --count command. 16 func (opts *AbisOptions) HandleCount(rCtx *output.RenderCtx) error { 17 testMode := opts.Globals.TestMode 18 19 fetchData := func(modelChan chan types.Modeler, errorChan chan error) { 20 count := uint64(0) 21 if testMode { 22 count = 199 23 } else { 24 vFunc := func(fn string, vP any) (bool, error) { 25 _, name := filepath.Split(fn) 26 if strings.HasSuffix(name, ".json") { 27 count++ 28 } 29 return true, nil 30 } 31 opts.ForEveryAbi(true, vFunc, nil) 32 } 33 34 s := types.Count{ 35 Count: count, 36 } 37 38 modelChan <- &s 39 } 40 41 return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) 42 }