Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): Add extraInfo to version cmd #18063

Merged
merged 15 commits into from
Oct 30, 2023
8 changes: 8 additions & 0 deletions simapp/simd/cmd/commands.go
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"errors"
"io"
"os"
Expand All @@ -26,6 +27,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand All @@ -38,10 +40,16 @@ func initRootCmd(
interfaceRegistry codectypes.InterfaceRegistry,
appCodec codec.Codec,
basicManager module.BasicManager,
extraInfo version.ExtraInfo,
) {
cfg := sdk.GetConfig()
cfg.Seal()

cmdContext := context.WithValue(rootCmd.Context(), "extraInfo", extraInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the context key should probably be a struct instead of a string.

rootCmd.SetContext(cmdContext)

rootCmd.AddCommand(version.NewVersionCommand())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might not need this as it's already being added by server.AddCommands


rootCmd.AddCommand(
genutilcli.InitCmd(basicManager),
NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}),
Expand Down
14 changes: 14 additions & 0 deletions version/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func NewVersionCommand() *cobra.Command {
return nil
}

extraInfo := extraInfoFromContext(cmd)
verInfo.ExtraInfo = &extraInfo

var (
bz []byte
err error
Expand Down Expand Up @@ -56,3 +59,14 @@ func NewVersionCommand() *cobra.Command {

return cmd
}

func extraInfoFromContext(cmd *cobra.Command) ExtraInfo {
ctx := cmd.Context()
if ctx != nil {
extraInfo, ok := ctx.Value("extraInfo").(ExtraInfo)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
if ok {
return extraInfo
}
}
return nil
}
4 changes: 4 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func getSDKVersion() string {
return sdkVersion
}

// ExtraInfo contains a set of extra information provided by apps
type ExtraInfo map[string]string

Comment on lines +61 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ExtraInfo type is defined as a map of string to string. This is a flexible structure that can hold various types of information. However, it might be worth considering if a more structured approach would be beneficial, especially if there are specific pieces of information that will always be included in the ExtraInfo. If that's the case, a struct with specific fields might be a better choice.

// Info defines the application version information.
type Info struct {
Name string `json:"name" yaml:"name"`
Expand All @@ -65,6 +68,7 @@ type Info struct {
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
CosmosSdkVersion string `json:"cosmos_sdk_version" yaml:"cosmos_sdk_version"`
ExtraInfo *ExtraInfo `json:"extra_info" yaml:"extra_info"`
}

func NewInfo() Info {
Expand Down
Loading