github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/list.go (about) 1 // Copyright 2016, 2024 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 * Parts of this file were auto generated. Edit only those parts of 6 * the code inside of 'EXISTING_CODE' tags. 7 */ 8 9 package cmd 10 11 // EXISTING_CODE 12 import ( 13 "os" 14 15 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals" 16 listPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/list" 17 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/caps" 18 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" 19 outputHelpers "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output/helpers" 20 "github.com/spf13/cobra" 21 ) 22 23 // EXISTING_CODE 24 25 // listCmd represents the list command 26 var listCmd = &cobra.Command{ 27 Use: usageList, 28 Long: longList, 29 Version: versionText, 30 PreRun: outputHelpers.PreRunWithJsonWriter("list", func() *globals.GlobalOptions { 31 return &listPkg.GetOptions().Globals 32 }), 33 RunE: file.RunWithFileSupport("list", listPkg.RunList, listPkg.ResetOptions), 34 PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions { 35 return &listPkg.GetOptions().Globals 36 }), 37 } 38 39 const usageList = `list [flags] <address> [address...] 40 41 Arguments: 42 addrs - one or more addresses (0x...) to list (required)` 43 44 const longList = `Purpose: 45 List every appearance of an address anywhere on the chain.` 46 47 const notesList = ` 48 Notes: 49 - An address must be either an ENS name or start with '0x' and be forty-two characters long. 50 - No other options are permitted when --silent is selected.` 51 52 func init() { 53 var capabilities caps.Capability // capabilities for chifra list 54 capabilities = capabilities.Add(caps.Default) 55 capabilities = capabilities.Add(caps.Names) 56 57 listCmd.Flags().SortFlags = false 58 59 listCmd.Flags().BoolVarP(&listPkg.GetOptions().Count, "count", "U", false, `display only the count of records for each monitor`) 60 listCmd.Flags().BoolVarP(&listPkg.GetOptions().NoZero, "no_zero", "z", false, `for the --count option only, suppress the display of zero appearance accounts`) 61 listCmd.Flags().BoolVarP(&listPkg.GetOptions().Bounds, "bounds", "b", false, `report first and last block this address appears`) 62 listCmd.Flags().BoolVarP(&listPkg.GetOptions().Unripe, "unripe", "u", false, `list transactions labeled unripe (i.e. less than 28 blocks old)`) 63 listCmd.Flags().BoolVarP(&listPkg.GetOptions().Silent, "silent", "s", false, `freshen the monitor only (no reporting)`) 64 listCmd.Flags().Uint64VarP(&listPkg.GetOptions().FirstRecord, "first_record", "c", 0, `the first record to process`) 65 listCmd.Flags().Uint64VarP(&listPkg.GetOptions().MaxRecords, "max_records", "e", 250, `the maximum number of records to process`) 66 listCmd.Flags().BoolVarP(&listPkg.GetOptions().Reversed, "reversed", "E", false, `produce results in reverse chronological order`) 67 listCmd.Flags().StringVarP(&listPkg.GetOptions().Publisher, "publisher", "P", "", `for some query options, the publisher of the index (hidden)`) 68 listCmd.Flags().Uint64VarP((*uint64)(&listPkg.GetOptions().FirstBlock), "first_block", "F", 0, `first block to export (inclusive, ignored when freshening)`) 69 listCmd.Flags().Uint64VarP((*uint64)(&listPkg.GetOptions().LastBlock), "last_block", "L", 0, `last block to export (inclusive, ignored when freshening)`) 70 if os.Getenv("TEST_MODE") != "true" { 71 _ = listCmd.Flags().MarkHidden("publisher") 72 } 73 globals.InitGlobals("list", listCmd, &listPkg.GetOptions().Globals, capabilities) 74 75 listCmd.SetUsageTemplate(UsageWithNotes(notesList)) 76 listCmd.SetOut(os.Stderr) 77 78 // EXISTING_CODE 79 // EXISTING_CODE 80 81 chifraCmd.AddCommand(listCmd) 82 }