github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/status.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  	statusPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/status"
    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  // statusCmd represents the status command
    26  var statusCmd = &cobra.Command{
    27  	Use:     usageStatus,
    28  	Long:    longStatus,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("status", func() *globals.GlobalOptions {
    31  		return &statusPkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("status", statusPkg.RunStatus, statusPkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &statusPkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageStatus = `status <mode> [mode...] [flags]
    40  
    41  Arguments:
    42    modes - the (optional) name of the binary cache to report on, terse otherwise
    43      One or more of [ index | blooms | blocks | transactions | traces | logs | statements | results | state | tokens | monitors | names | abis | slurps | staging | unripe | maps | some | all ]`
    44  
    45  const longStatus = `Purpose:
    46    Report on the state of the internal binary caches.`
    47  
    48  const notesStatus = `
    49  Notes:
    50    - The some mode includes index, monitors, names, slurps, and abis.
    51    - If no mode is supplied, a terse report is generated.`
    52  
    53  func init() {
    54  	var capabilities caps.Capability // capabilities for chifra status
    55  	capabilities = capabilities.Add(caps.Default)
    56  
    57  	statusCmd.Flags().SortFlags = false
    58  
    59  	statusCmd.Flags().BoolVarP(&statusPkg.GetOptions().Diagnose, "diagnose", "d", false, `same as the default but with additional diagnostics`)
    60  	statusCmd.Flags().Uint64VarP(&statusPkg.GetOptions().FirstRecord, "first_record", "c", 0, `the first record to process`)
    61  	statusCmd.Flags().Uint64VarP(&statusPkg.GetOptions().MaxRecords, "max_records", "e", 10000, `the maximum number of records to process`)
    62  	statusCmd.Flags().BoolVarP(&statusPkg.GetOptions().Chains, "chains", "a", false, `include a list of chain configurations in the output`)
    63  	statusCmd.Flags().BoolVarP(&statusPkg.GetOptions().Healthcheck, "healthcheck", "k", false, `an alias for the diagnose endpoint`)
    64  	globals.InitGlobals("status", statusCmd, &statusPkg.GetOptions().Globals, capabilities)
    65  
    66  	statusCmd.SetUsageTemplate(UsageWithNotes(notesStatus))
    67  	statusCmd.SetOut(os.Stderr)
    68  
    69  	// EXISTING_CODE
    70  	// EXISTING_CODE
    71  
    72  	chifraCmd.AddCommand(statusCmd)
    73  }