github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/abis.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  	abisPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/abis"
    16  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/globals"
    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  // abisCmd represents the abis command
    26  var abisCmd = &cobra.Command{
    27  	Use:     usageAbis,
    28  	Long:    longAbis,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("abis", func() *globals.GlobalOptions {
    31  		return &abisPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("abis", abisPkg.RunAbis, abisPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &abisPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageAbis = `abis [flags] <address> [address...]
    40  
    41  Arguments:
    42    addrs - a list of one or more smart contracts whose ABIs to display (required)`
    43  
    44  const longAbis = `Purpose:
    45    Fetches the ABI for a smart contract.`
    46  
    47  const notesAbis = `
    48  Notes:
    49    - Search for either four byte signatures or event signatures with the --find option.`
    50  
    51  func init() {
    52  	var capabilities caps.Capability // capabilities for chifra abis
    53  	capabilities = capabilities.Add(caps.Default)
    54  	capabilities = capabilities.Add(caps.Caching)
    55  	capabilities = capabilities.Add(caps.Names)
    56  
    57  	abisCmd.Flags().SortFlags = false
    58  
    59  	abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().Known, "known", "k", false, `load common 'known' ABIs from cache`)
    60  	abisCmd.Flags().StringVarP(&abisPkg.GetOptions().ProxyFor, "proxy_for", "r", "", `redirects the query to this implementation`)
    61  	abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().List, "list", "l", false, `a list of downloaded abi files`)
    62  	abisCmd.Flags().BoolVarP(&abisPkg.GetOptions().Count, "count", "c", false, `show the number of abis downloaded`)
    63  	abisCmd.Flags().StringSliceVarP(&abisPkg.GetOptions().Find, "find", "f", nil, `search for function or event declarations given a four- or 32-byte code(s)`)
    64  	abisCmd.Flags().StringSliceVarP(&abisPkg.GetOptions().Hint, "hint", "n", nil, `for the --find option only, provide hints to speed up the search`)
    65  	abisCmd.Flags().StringVarP(&abisPkg.GetOptions().Encode, "encode", "e", "", `generate the 32-byte encoding for a given cannonical function or event signature`)
    66  	globals.InitGlobals("abis", abisCmd, &abisPkg.GetOptions().Globals, capabilities)
    67  
    68  	abisCmd.SetUsageTemplate(UsageWithNotes(notesAbis))
    69  	abisCmd.SetOut(os.Stderr)
    70  
    71  	// EXISTING_CODE
    72  	// EXISTING_CODE
    73  
    74  	chifraCmd.AddCommand(abisCmd)
    75  }