github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/chunks.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  	chunksPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/chunks"
    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  // chunksCmd represents the chunks command
    26  var chunksCmd = &cobra.Command{
    27  	Use:     usageChunks,
    28  	Long:    longChunks,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("chunks", func() *globals.GlobalOptions {
    31  		return &chunksPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("chunks", chunksPkg.RunChunks, chunksPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &chunksPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageChunks = `chunks <mode> [flags] [blocks...] [address...]
    40  
    41  Arguments:
    42    mode - the type of data to process (required)
    43      One of [ manifest | index | blooms | pins | addresses | appearances | stats ]
    44    blocks - an optional list of blocks to intersect with chunk ranges`
    45  
    46  const longChunks = `Purpose:
    47    Manage, investigate, and display the Unchained Index.`
    48  
    49  const notesChunks = `
    50  Notes:
    51    - Mode determines which type of data to display or process.
    52    - Certain options are only available in certain modes.
    53    - If blocks are provided, only chunks intersecting with those blocks are displayed.
    54    - The --truncate option updates the manifest and removes local data, but does not alter remote pins.
    55    - The --belongs option is only available in the index mode.
    56    - The --first_block and --last_block options apply only to addresses, appearances, and index --belongs mode.
    57    - The --pin option requires a locally running IPFS node or a pinning service API key.
    58    - The --publish option requires a private key.
    59    - The --publisher option is ignored with the --publish option since the sender of the transaction is recorded as the publisher.
    60    - Without --rewrite, the manifest is written to the temporary cache. With it, the manifest is rewritten to the index folder.`
    61  
    62  func init() {
    63  	var capabilities caps.Capability // capabilities for chifra chunks
    64  	capabilities = capabilities.Add(caps.Default)
    65  
    66  	chunksCmd.Flags().SortFlags = false
    67  
    68  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Check, "check", "c", false, `check the manifest, index, or blooms for internal consistency`)
    69  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Pin, "pin", "i", false, `pin the manifest or each index chunk and bloom`)
    70  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Publish, "publish", "p", false, `publish the manifest to the Unchained Index smart contract`)
    71  	chunksCmd.Flags().StringVarP(&chunksPkg.GetOptions().Publisher, "publisher", "P", "", `for some query options, the publisher of the index (hidden)`)
    72  	chunksCmd.Flags().Uint64VarP((*uint64)(&chunksPkg.GetOptions().Truncate), "truncate", "n", 0, `truncate the entire index at this block (requires a block identifier) (hidden)`)
    73  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Remote, "remote", "r", false, `prior to processing, retrieve the manifest from the Unchained Index smart contract`)
    74  	chunksCmd.Flags().StringSliceVarP(&chunksPkg.GetOptions().Belongs, "belongs", "b", nil, `in index mode only, checks the address(es) for inclusion in the given index chunk`)
    75  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Diff, "diff", "f", false, `compare two index portions (see notes) (hidden)`)
    76  	chunksCmd.Flags().Uint64VarP((*uint64)(&chunksPkg.GetOptions().FirstBlock), "first_block", "F", 0, `first block to process (inclusive)`)
    77  	chunksCmd.Flags().Uint64VarP((*uint64)(&chunksPkg.GetOptions().LastBlock), "last_block", "L", 0, `last block to process (inclusive)`)
    78  	chunksCmd.Flags().Uint64VarP(&chunksPkg.GetOptions().MaxAddrs, "max_addrs", "m", 0, `the max number of addresses to process in a given chunk`)
    79  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Deep, "deep", "d", false, `if true, dig more deeply during checking (manifest only)`)
    80  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Rewrite, "rewrite", "e", false, `for the --pin --deep mode only, writes the manifest back to the index folder (see notes)`)
    81  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().List, "list", "l", false, `for the pins mode only, list the remote pins (hidden)`)
    82  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Unpin, "unpin", "u", false, `for the pins mode only, if true reads local ./unpins file for valid CIDs and remotely unpins each (skips non-CIDs) (hidden)`)
    83  	chunksCmd.Flags().BoolVarP(&chunksPkg.GetOptions().Count, "count", "U", false, `for certain modes only, display the count of records`)
    84  	chunksCmd.Flags().StringVarP(&chunksPkg.GetOptions().Tag, "tag", "t", "", `visits each chunk and updates the headers with the supplied version string (vX.Y.Z-str) (hidden)`)
    85  	chunksCmd.Flags().Float64VarP(&chunksPkg.GetOptions().Sleep, "sleep", "s", 0.0, `for --remote pinning only, seconds to sleep between API calls`)
    86  	if os.Getenv("TEST_MODE") != "true" {
    87  		_ = chunksCmd.Flags().MarkHidden("publisher")
    88  		_ = chunksCmd.Flags().MarkHidden("truncate")
    89  		_ = chunksCmd.Flags().MarkHidden("diff")
    90  		_ = chunksCmd.Flags().MarkHidden("list")
    91  		_ = chunksCmd.Flags().MarkHidden("unpin")
    92  		_ = chunksCmd.Flags().MarkHidden("tag")
    93  	}
    94  	globals.InitGlobals("chunks", chunksCmd, &chunksPkg.GetOptions().Globals, capabilities)
    95  
    96  	chunksCmd.SetUsageTemplate(UsageWithNotes(notesChunks))
    97  	chunksCmd.SetOut(os.Stderr)
    98  
    99  	// EXISTING_CODE
   100  	// EXISTING_CODE
   101  
   102  	chifraCmd.AddCommand(chunksCmd)
   103  }