github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/explore.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  	explorePkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/explore"
    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  // exploreCmd represents the explore command
    26  var exploreCmd = &cobra.Command{
    27  	Use:     usageExplore,
    28  	Long:    longExplore,
    29  	Version: versionText,
    30  	PreRun: outputHelpers.PreRunWithJsonWriter("explore", func() *globals.GlobalOptions {
    31  		return &explorePkg.GetOptions().Globals
    32  	}),
    33  	RunE: file.RunWithFileSupport("explore", explorePkg.RunExplore, explorePkg.ResetOptions),
    34  	PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions {
    35  		return &explorePkg.GetOptions().Globals
    36  	}),
    37  }
    38  
    39  const usageExplore = `explore [flags] [terms...]
    40  
    41  Arguments:
    42    terms - one or more address, name, block, or transaction identifier`
    43  
    44  const longExplore = `Purpose:
    45    Open a local or remote explorer for one or more addresses, blocks, or transactions.`
    46  
    47  const notesExplore = ``
    48  
    49  func init() {
    50  	var capabilities caps.Capability // capabilities for chifra explore
    51  	capabilities = capabilities.Add(caps.Default)
    52  
    53  	exploreCmd.Flags().SortFlags = false
    54  
    55  	exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().NoOpen, "no_open", "n", false, `return the URL without opening it`)
    56  	exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Local, "local", "l", false, `open the local TrueBlocks explorer`)
    57  	exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Google, "google", "g", false, `search google excluding popular blockchain explorers`)
    58  	exploreCmd.Flags().BoolVarP(&explorePkg.GetOptions().Dalle, "dalle", "d", false, `open the address to the DalleDress explorer (hidden)`)
    59  	if os.Getenv("TEST_MODE") != "true" {
    60  		_ = exploreCmd.Flags().MarkHidden("dalle")
    61  	}
    62  	globals.InitGlobals("explore", exploreCmd, &explorePkg.GetOptions().Globals, capabilities)
    63  
    64  	exploreCmd.SetUsageTemplate(UsageWithNotes(notesExplore))
    65  	exploreCmd.SetOut(os.Stderr)
    66  
    67  	// EXISTING_CODE
    68  	_ = exploreCmd.Flags().MarkHidden("verbose")
    69  	_ = exploreCmd.Flags().MarkHidden("fmt")
    70  	// EXISTING_CODE
    71  
    72  	chifraCmd.AddCommand(exploreCmd)
    73  }