diff --git a/src/apps/chifra/internal/config/README.md b/src/apps/chifra/internal/config/README.md index 88c9190a11..166cd924cb 100644 --- a/src/apps/chifra/internal/config/README.md +++ b/src/apps/chifra/internal/config/README.md @@ -20,6 +20,7 @@ Arguments: Flags: -a, --paths show the configuration paths for the system + -d, --dump dump the configuration to stdout -x, --fmt string export format, one of [none|json*|txt|csv] -v, --verbose enable verbose output -h, --help display this help screen diff --git a/src/apps/chifra/pkg/config/config.go b/src/apps/chifra/pkg/config/config.go index ff0e22e2bc..7f367a890c 100644 --- a/src/apps/chifra/pkg/config/config.go +++ b/src/apps/chifra/pkg/config/config.go @@ -195,7 +195,7 @@ func pathFromXDG(envVar string) (string, error) { absXDGPath, err := filepath.Abs(xdg) if err != nil { return "", usage.Usage("The {0} value ({1}), could not be interpreted as an absolute path.", envVar, xdg) - } + } if _, err := os.Stat(absXDGPath); err != nil { return "", usage.Usage("The {0} folder ({1}) must exist.", envVar, absXDGPath) diff --git a/src/apps/chifra/pkg/types/types_config.go b/src/apps/chifra/pkg/types/types_config.go new file mode 100644 index 0000000000..68c3c8ba5f --- /dev/null +++ b/src/apps/chifra/pkg/types/types_config.go @@ -0,0 +1,53 @@ +// 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 { + Version configtypes.VersionGroup `json:"version" toml:"version"` + Settings configtypes.SettingsGroup `json:"settings" toml:"settings"` + Keys map[string]configtypes.KeyGroup `json:"keys" toml:"keys"` + Pinning configtypes.PinningGroup `json:"pinning" toml:"pinning"` + Unchained configtypes.UnchainedGroup `json:"unchained" toml:"unchained,omitempty" comment:"Do not edit these values unless instructed to do so."` + Chains map[string]configtypes.ChainGroup `json:"chains" toml:"chains"` +} + +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() { +} + +func (s *Config) ShallowCopy() Config { + return *s +} diff --git a/src/dev_tools/sdkFuzzer/config.go b/src/dev_tools/sdkFuzzer/config.go index eebdc850f2..436375eb7d 100644 --- a/src/dev_tools/sdkFuzzer/config.go +++ b/src/dev_tools/sdkFuzzer/config.go @@ -54,11 +54,11 @@ func TestConfig(which, value, fn string, opts *sdk.ConfigOptions) { ReportOkay(fn) } } - case "session": - if session, _, err := opts.ConfigSession(); err != nil { + case "dump": + if dump, _, err := opts.ConfigDump(); err != nil { ReportError(fn, opts, err) } else { - if err := SaveToFile[types.Session](fn, session); err != nil { + if err := SaveToFile[types.Config](fn, dump); err != nil { ReportError2(fn, err) } else { ReportOkay(fn)