generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): go backwards by remvoving logic query autocli
- Loading branch information
Showing
6 changed files
with
130 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.