github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/logs.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  	logsPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/logs"
    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  // logsCmd represents the logs command
    26  var logsCmd = &cobra.Command{
    27  	Use:     usageLogs,
    28  	Long:    longLogs,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("logs", func() *globals.GlobalOptions {
    31  		return &logsPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("logs", logsPkg.RunLogs, logsPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &logsPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageLogs = `logs [flags] <tx_id> [tx_id...]
    40  
    41  Arguments:
    42    transactions - a space-separated list of one or more transaction identifiers (required)`
    43  
    44  const longLogs = `Purpose:
    45    Retrieve logs for the given transaction(s).`
    46  
    47  const notesLogs = `
    48  Notes:
    49    - The transactions list may be one or more transaction hashes, blockNumber.transactionID pairs, or a blockHash.transactionID pairs.
    50    - This tool checks for valid input syntax, but does not check that the transaction requested actually exists.
    51    - If the queried node does not store historical state, the results for most older transactions are undefined.
    52    - If you specify a 32-byte hash, it will be assumed to be a transaction hash, if it is not, the hash will be used as a topic.`
    53  
    54  func init() {
    55  	var capabilities caps.Capability // capabilities for chifra logs
    56  	capabilities = capabilities.Add(caps.Default)
    57  	capabilities = capabilities.Add(caps.Caching)
    58  	capabilities = capabilities.Add(caps.Names)
    59  
    60  	logsCmd.Flags().SortFlags = false
    61  
    62  	logsCmd.Flags().StringSliceVarP(&logsPkg.GetOptions().Emitter, "emitter", "m", nil, `filter logs to show only those logs emitted by the given address(es)`)
    63  	logsCmd.Flags().StringSliceVarP(&logsPkg.GetOptions().Topic, "topic", "B", nil, `filter logs to show only those with this topic(s)`)
    64  	logsCmd.Flags().BoolVarP(&logsPkg.GetOptions().Articulate, "articulate", "a", false, `articulate the retrieved data if ABIs can be found`)
    65  	globals.InitGlobals("logs", logsCmd, &logsPkg.GetOptions().Globals, capabilities)
    66  
    67  	logsCmd.SetUsageTemplate(UsageWithNotes(notesLogs))
    68  	logsCmd.SetOut(os.Stderr)
    69  
    70  	// EXISTING_CODE
    71  	// EXISTING_CODE
    72  
    73  	chifraCmd.AddCommand(logsCmd)
    74  }