github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/cmd/names.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 namesPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/internal/names" 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 // namesCmd represents the names command 26 var namesCmd = &cobra.Command{ 27 Use: usageNames, 28 Long: longNames, 29 Version: versionText, 30 PreRun: outputHelpers.PreRunWithJsonWriter("names", func() *globals.GlobalOptions { 31 return &namesPkg.GetOptions().Globals 32 }), 33 RunE: file.RunWithFileSupport("names", namesPkg.RunNames, namesPkg.ResetOptions), 34 PostRun: outputHelpers.PostRunWithJsonWriter(func() *globals.GlobalOptions { 35 return &namesPkg.GetOptions().Globals 36 }), 37 } 38 39 const usageNames = `names [flags] <term> [term...] 40 41 Arguments: 42 terms - a space separated list of one or more search terms (required)` 43 44 const longNames = `Purpose: 45 Query addresses or names of well-known accounts.` 46 47 const notesNames = ` 48 Notes: 49 - The tool will accept up to three terms, each of which must match against any field in the database. 50 - The --match_case option enables case sensitive matching.` 51 52 func init() { 53 var capabilities caps.Capability // capabilities for chifra names 54 capabilities = capabilities.Add(caps.Default) 55 56 namesCmd.Flags().SortFlags = false 57 58 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Expand, "expand", "e", false, `expand search to include all fields (search name, address, and symbol otherwise)`) 59 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().MatchCase, "match_case", "m", false, `do case-sensitive search`) 60 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().All, "all", "a", false, `include all (including custom) names in the search`) 61 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Custom, "custom", "c", false, `include only custom named accounts in the search`) 62 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Prefund, "prefund", "p", false, `include prefund accounts in the search`) 63 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Addr, "addr", "s", false, `display only addresses in the results (useful for scripting, assumes --no_header)`) 64 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Tags, "tags", "g", false, `export the list of tags and subtags only`) 65 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Clean, "clean", "C", false, `clean the data (addrs to lower case, sort by addr)`) 66 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Regular, "regular", "r", false, `only available with --clean, cleans regular names database`) 67 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().DryRun, "dry_run", "d", false, `only available with --clean or --autoname, outputs changes to stdout instead of updating databases`) 68 namesCmd.Flags().StringVarP(&namesPkg.GetOptions().Autoname, "autoname", "A", "", `an address assumed to be a token, added automatically to names database if true`) 69 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Create, "create", "", false, `create a new name record (hidden)`) 70 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Update, "update", "", false, `edit an existing name (hidden)`) 71 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Delete, "delete", "", false, `delete a name, but do not remove it (hidden)`) 72 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Undelete, "undelete", "", false, `undelete a previously deleted name (hidden)`) 73 namesCmd.Flags().BoolVarP(&namesPkg.GetOptions().Remove, "remove", "", false, `remove a previously deleted name (hidden)`) 74 if os.Getenv("TEST_MODE") != "true" { 75 _ = namesCmd.Flags().MarkHidden("create") 76 _ = namesCmd.Flags().MarkHidden("update") 77 _ = namesCmd.Flags().MarkHidden("delete") 78 _ = namesCmd.Flags().MarkHidden("undelete") 79 _ = namesCmd.Flags().MarkHidden("remove") 80 } 81 globals.InitGlobals("names", namesCmd, &namesPkg.GetOptions().Globals, capabilities) 82 83 namesCmd.SetUsageTemplate(UsageWithNotes(notesNames)) 84 namesCmd.SetOut(os.Stderr) 85 86 // EXISTING_CODE 87 // EXISTING_CODE 88 89 chifraCmd.AddCommand(namesCmd) 90 }