Skip to content

Commit

Permalink
fix(cli): go backwards by remvoving logic query autocli
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 23, 2024
1 parent ad04ce4 commit 46d4b66
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 54 deletions.
44 changes: 0 additions & 44 deletions x/logic/autocli.go

This file was deleted.

28 changes: 28 additions & 0 deletions x/logic/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

"github.com/okp4/okp4d/x/logic/types"
)

// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
// Group logic queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdQueryAsk())

return cmd
}
57 changes: 57 additions & 0 deletions x/logic/client/cli/query_ask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cli

import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"

"github.com/okp4/okp4d/x/logic/types"
)

var program string

func CmdQueryAsk() *cobra.Command {
cmd := &cobra.Command{
Use: "ask [query]",
Short: "executes a logic query and returns the solutions found.",
Long: `Executes the [query] and return the solution(s) found.
Optionally, a program can be transmitted, which will be interpreted before the query is processed.
Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
is charged for this, but the execution is constrained by the current limits configured in the module (that you can
query).`,
Example: fmt.Sprintf(`$ %s query %s ask "chain_id(X)." # returns the chain-id`,
version.AppName,
types.ModuleName),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
query := args[0]
queryClient := types.NewQueryServiceClient(clientCtx)

res, err := queryClient.Ask(context.Background(), &types.QueryServiceAskRequest{
Program: program,
Query: query,
})
if err != nil {
return
}

return clientCtx.PrintProto(res)
},
}

cmd.Flags().StringVar(
&program,
"program",
"",
`reads the program from the given string.`)

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
36 changes: 36 additions & 0 deletions x/logic/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"context"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/okp4/okp4d/x/logic/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryServiceClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryServiceParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
9 changes: 9 additions & 0 deletions x/logic/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"encoding/json"
"fmt"

"github.com/okp4/okp4d/x/logic/client/cli"
"github.com/spf13/cobra"

"github.com/grpc-ecosystem/grpc-gateway/runtime"

"cosmossdk.io/core/appmodule"
Expand Down Expand Up @@ -77,6 +80,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
_ = types.RegisterQueryServiceHandlerClient(context.Background(), mux, types.NewQueryServiceClient(clientCtx))
}

// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users
// to generate new queries to the subset of the state defined by the module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions x/logic/types/types.go

This file was deleted.

0 comments on commit 46d4b66

Please sign in to comment.