Skip to content

Commit

Permalink
Implements chifra config show
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Sep 27, 2023
1 parent abf9ced commit 0149094
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/apps/chifra/internal/config/handle_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package configPkg

import (
"fmt"

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

func (opts *ConfigOptions) HandleShow() error {
fn := config.PathToRootConfig() + "trueBlocks.toml"
fmt.Printf("%s", file.AsciiFileToString(fn))
return nil
}
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 @@ -62,8 +62,8 @@ func (opts *ConfigOptions) ConfigInternal() (err error, handled bool) {
err = opts.HandlePaths()
} else if opts.Mode == "edit" {
err = opts.HandleEdit()
} else {
logger.Warn("The config tool is current unavailable. Please use the 'chifra status' tool instead.")
} else if opts.Mode == "show" {
err = opts.HandleShow()
}
// EXISTING_CODE
timer.Report(msg)
Expand Down
7 changes: 5 additions & 2 deletions src/apps/chifra/internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ func (opts *ConfigOptions) validateConfig() error {
return validate.Usage("chain {0} is not properly configured.", chain)
}

err := validate.ValidateEnum("modes", opts.Mode, "[show|edit]")
if err != nil {
if err := validate.ValidateEnum("modes", opts.Mode, "[show|edit]"); err != nil {
return err
}

if !opts.Globals.TestMode && opts.Mode == "edit" && os.Getenv("EDITOR") == "" {
return validate.Usage("You must set the EDITOR environment variable to use the 'edit' mode.")
}

// if len(opts.Mode) == 0 || !opts.Paths {
// return validate.Usage("You must supply either {0} or {1}.", "a mode", "--paths")
// }

return opts.Globals.Validate()
}

0 comments on commit 0149094

Please sign in to comment.