Skip to content

Commit

Permalink
Merge pull request #3904 from TrueBlocks/goMaker-2
Browse files Browse the repository at this point in the history
chifra config --session
  • Loading branch information
tjayrush authored Oct 29, 2024
2 parents 4b6475b + e080e49 commit 58452a6
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdk
4 changes: 4 additions & 0 deletions src/apps/chifra/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func init() {
configCmd.Flags().SortFlags = false

configCmd.Flags().BoolVarP(&configPkg.GetOptions().Paths, "paths", "a", false, `show the configuration paths for the system`)
configCmd.Flags().BoolVarP(&configPkg.GetOptions().Session, "session", "s", false, `standin for ui code - no purpose (hidden)`)
if os.Getenv("TEST_MODE") != "true" {
_ = configCmd.Flags().MarkHidden("session")
}
globals.InitGlobals("config", configCmd, &configPkg.GetOptions().Globals, capabilities)

configCmd.SetUsageTemplate(UsageWithNotes(notesConfig))
Expand Down
3 changes: 3 additions & 0 deletions src/apps/chifra/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/panjf2000/ants/v2 v2.10.0
github.com/pelletier/go-toml/v2 v2.2.2
github.com/spf13/cobra v1.7.0
github.com/wailsapp/wails/v2 v2.8.2
github.com/wealdtech/go-ens/v3 v3.5.2
golang.org/x/crypto v0.25.0
golang.org/x/term v0.22.0
Expand Down Expand Up @@ -46,6 +47,8 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.8.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/leaanthony/u v1.1.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.27.8 // indirect
Expand Down
10 changes: 10 additions & 0 deletions src/apps/chifra/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI=
github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand All @@ -451,6 +455,8 @@ github.com/libp2p/go-libp2p v0.27.8/go.mod h1:eCFFtd0s5i/EVKR7+5Ki8bM7qwkNW3TPTT
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -609,6 +615,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
Expand Down Expand Up @@ -685,6 +693,8 @@ github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBn
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/wailsapp/wails/v2 v2.9.2 h1:Xb5YRTos1w5N7DTMyYegWaGukCP2fIaX9WF21kPPF2k=
github.com/wailsapp/wails/v2 v2.9.2/go.mod h1:uehvlCwJSFcBq7rMCGfk4rxca67QQGsbg5Nm4m9UnBs=
github.com/wealdtech/go-ens/v3 v3.5.2 h1:70CAIiG9hcue6Ja5wxWcnCwi5UfmiW5NH1styxpAbgU=
github.com/wealdtech/go-ens/v3 v3.5.2/go.mod h1:4qs2EEeTmv538RoB8QjLS9w5N1HSXS253qhLyNEShBs=
github.com/wealdtech/go-multicodec v1.4.0 h1:iq5PgxwssxnXGGPTIK1srvt6U5bJwIp7k6kBrudIWxg=
Expand Down
14 changes: 14 additions & 0 deletions src/apps/chifra/internal/config/handle_session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package configPkg

import (
"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 {
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
modelChan <- &types.Session{}
}
return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts())
}
4 changes: 4 additions & 0 deletions src/apps/chifra/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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
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 @@ -41,6 +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)
opts.Conn.TestLog(opts.getCaches())
opts.Globals.TestLog()
}
Expand Down Expand Up @@ -70,6 +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
default:
if !copy.Globals.Caps.HasKey(key) {
err := validate.Usage("Invalid key ({0}) in {1} route.", key, "config")
Expand Down
2 changes: 2 additions & 0 deletions src/apps/chifra/internal/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +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 {
err = opts.HandleShow(rCtx)
}
Expand Down
Loading

0 comments on commit 58452a6

Please sign in to comment.