-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add raw query command functionality (#328)
- Loading branch information
1 parent
90b3463
commit e6f5bad
Showing
6 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
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 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,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
lclient "github.com/uselagoon/machinery/api/lagoon/client" | ||
) | ||
|
||
var rawCmd = &cobra.Command{ | ||
Use: "raw", | ||
Aliases: []string{"r"}, | ||
Short: "Run a custom query or mutation", | ||
Long: `Run a custom query or mutation. | ||
The output of this command will be the JSON response from the API`, | ||
PreRunE: func(_ *cobra.Command, _ []string) error { | ||
return validateTokenE(cmdLagoon) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
return err | ||
} | ||
raw, err := cmd.Flags().GetString("raw") | ||
if err != nil { | ||
return err | ||
} | ||
if err := requiredInputCheck("Raw query or mutation", raw); err != nil { | ||
return err | ||
} | ||
current := lagoonCLIConfig.Current | ||
token := lagoonCLIConfig.Lagoons[current].Token | ||
lc := lclient.New( | ||
lagoonCLIConfig.Lagoons[current].GraphQL, | ||
lagoonCLIVersion, | ||
&token, | ||
debug) | ||
if err != nil { | ||
return err | ||
} | ||
rawResp, err := lc.ProcessRaw(context.TODO(), raw, nil) | ||
if err != nil { | ||
return err | ||
} | ||
r, err := json.Marshal(rawResp) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(r)) | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rawCmd.Flags().String("raw", "", "The raw query or mutation to run") | ||
} |
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 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 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,41 @@ | ||
## lagoon raw | ||
|
||
Run a custom query or mutation | ||
|
||
### Synopsis | ||
|
||
Run a custom query or mutation. | ||
The output of this command will be the JSON response from the API | ||
|
||
``` | ||
lagoon raw [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for raw | ||
--raw string The raw query or mutation to run | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config-file string Path to the config file to use (must be *.yml or *.yaml) | ||
--debug Enable debugging output (if supported) | ||
-e, --environment string Specify an environment to use | ||
--force Force yes on prompts (if supported) | ||
-l, --lagoon string The Lagoon instance to interact with | ||
--no-header No header on table (if supported) | ||
--output-csv Output as CSV (if supported) | ||
--output-json Output as JSON (if supported) | ||
--pretty Make JSON pretty (if supported) | ||
-p, --project string Specify a project to use | ||
--skip-update-check Skip checking for updates | ||
-i, --ssh-key string Specify path to a specific SSH key to use for lagoon authentication | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [lagoon](lagoon.md) - Command line integration for Lagoon | ||
|
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