Skip to content

Commit

Permalink
Updates for chifra config --dump
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Nov 25, 2024
1 parent 67e9e35 commit aeb31f5
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 455 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package configPkg

import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

// HandleSession returns an empty session
func (opts *ConfigOptions) HandleSession(rCtx *output.RenderCtx) error {
// HandleDump dumps a config to the screen
func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error {
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
modelChan <- &types.Session{}
var s types.Config
s.Config = *config.GetRootConfig()
modelChan <- &s
}

opts.Globals.NoHeader = true
return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts())
}
11 changes: 7 additions & 4 deletions src/apps/chifra/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
type ConfigOptions struct {
Mode string `json:"mode,omitempty"` // Either show or edit the configuration
Paths bool `json:"paths,omitempty"` // Show the configuration paths for the system
Session bool `json:"session,omitempty"` // Standin for ui code - no purpose
Dump bool `json:"dump,omitempty"` // Dump the configuration to stdout
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Conn *rpc.Connection `json:"conn,omitempty"` // The connection to the RPC server
BadFlag error `json:"badFlag,omitempty"` // An error flag if needed
Expand All @@ -42,7 +42,7 @@ var defaultConfigOptions = ConfigOptions{}
func (opts *ConfigOptions) testLog() {
logger.TestLog(len(opts.Mode) > 0, "Mode: ", opts.Mode)
logger.TestLog(opts.Paths, "Paths: ", opts.Paths)
logger.TestLog(opts.Session, "Session: ", opts.Session)
logger.TestLog(opts.Dump, "Dump: ", opts.Dump)
opts.Conn.TestLog(opts.getCaches())
opts.Globals.TestLog()
}
Expand Down Expand Up @@ -72,8 +72,8 @@ func ConfigFinishParseInternal(w io.Writer, values url.Values) *ConfigOptions {
opts.Mode = value[0]
case "paths":
opts.Paths = true
case "session":
opts.Session = true
case "dump":
opts.Dump = true
default:
if !copy.Globals.Caps.HasKey(key) {
err := validate.Usage("Invalid key ({0}) in {1} route.", key, "config")
Expand Down Expand Up @@ -118,6 +118,9 @@ func configFinishParse(args []string) *ConfigOptions {
if len(opts.Mode) == 0 {
opts.Mode = "<empty>"
}
if opts.Dump {
opts.Globals.Format = "json"
}
// EXISTING_CODE
if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" {
opts.Globals.Format = defFmt
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (opts *ConfigOptions) ConfigInternal(rCtx *output.RenderCtx) error {
// EXISTING_CODE
if opts.Paths {
err = opts.HandlePaths(rCtx)
} else if opts.Session {
err = opts.HandleSession(rCtx)
} else if opts.Dump {
err = opts.HandleDump(rCtx)
} else {
err = opts.HandleShow(rCtx)
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/init/handle_init_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (opts *InitOptions) updateLocalManifest(existing, remote *manifest.Manifest
}
}

return copy.SaveManifest(chain, config.PathToManifest(chain))
return copy.SaveManifest(chain, config.PathToManifestFile(chain))
}

var spaces = strings.Repeat(" ", 55)
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/config/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func PathToChainConfig(chain string) (string, error) {
return cfgFolder, err
}

// PathToManifest returns the path to the manifest database per chain
func PathToManifest(chain string) string {
// PathToManifestFile returns the path to the manifest database per chain
func PathToManifestFile(chain string) string {
return filepath.Join(PathToIndex(chain), "manifest.json")
}

Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/configtypes/chain_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ChainGroup struct {
IpfsGateway string `json:"ipfsGateway" toml:"ipfsGateway,omitempty"`
KeyEndpoint string `json:"keyEndpoint" toml:"keyEndpoint,omitempty"`
LocalExplorer string `json:"localExplorer" toml:"localExplorer,omitempty"`
RemoteExplorer string `json:"removeExplorer" toml:"remoteExplorer,omitempty"`
RemoteExplorer string `json:"remoteExplorer" toml:"remoteExplorer,omitempty"`
RpcProvider string `json:"rpcProvider" toml:"rpcProvider"`
Symbol string `json:"symbol" toml:"symbol"`
Scrape ScrapeSettings `json:"scrape" toml:"scrape"`
Expand Down
4 changes: 4 additions & 0 deletions src/apps/chifra/pkg/types/types_abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ func (s *Abi) FinishUnmarshal() {
}

// EXISTING_CODE
func (s *Abi) ShallowCopy() Abi {
return *s
}

// EXISTING_CODE
4 changes: 4 additions & 0 deletions src/apps/chifra/pkg/types/types_chunkstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ func (s *ChunkStats) FinishUnmarshal() {
}

// EXISTING_CODE
func (s *ChunkStats) ShallowCopy() ChunkStats {
return *s
}

// EXISTING_CODE
44 changes: 44 additions & 0 deletions src/apps/chifra/pkg/types/types_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
package types

import (
"encoding/json"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes"
)

type Config struct {
configtypes.Config
}

func (s Config) String() string {
bytes, _ := json.Marshal(s)
return string(bytes)
}

func (s *Config) Model(chain, format string, verbose bool, extraOpts map[string]any) Model {
// keys := map[string]any{}
// for key, value := range s.Keys {
// keys[key] = value
// }
c := map[string]any{}
for key, value := range s.Chains {
c[key] = value
}
return Model{
Data: map[string]any{
"version": s.Version,
"settings": s.Settings,
"keys": s.Keys,
"pinnging": s.Pinning,
"unchained": s.Unchained,
"chains": s.Chains,
},
Order: []string{},
}
}

func (s *Config) FinishUnmarshal() {
}
8 changes: 8 additions & 0 deletions src/apps/chifra/pkg/types/types_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ func (s *Manifest) FinishUnmarshal() {
}

// EXISTING_CODE
func (s *Manifest) ShallowCopy() Manifest {
return Manifest{
Chain: s.Chain,
Specification: s.Specification,
Version: s.Version,
}
}

// EXISTING_CODE
Loading

0 comments on commit aeb31f5

Please sign in to comment.