diff --git a/Makefile b/Makefile index 11200089..cdc78c0a 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,8 @@ build-linux: test build-darwin: test GO111MODULE=on CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOCMD) build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-darwin-amd64 -v -docs: test build - GO111MODULE=on $(GOCMD) run main.go --docs +docs: test + LAGOON_GEN_DOCS=true GO111MODULE=on $(GOCMD) run main.go --docs tidy: GO111MODULE=on $(GOCMD) mod tidy diff --git a/cmd/raw.go b/cmd/raw.go new file mode 100644 index 00000000..f79767a3 --- /dev/null +++ b/cmd/raw.go @@ -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") +} diff --git a/cmd/root.go b/cmd/root.go index a98b4109..a5c8eb55 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -38,6 +38,7 @@ var configExtension = ".yml" var createConfig bool var userPath string var configFilePath string +var commandsFilePath = ".lagoon-cli/commands" var updateDocURL = "https://uselagoon.github.io/lagoon-cli" var skipUpdateCheck bool @@ -195,6 +196,7 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e rootCmd.AddCommand(exportCmd) rootCmd.AddCommand(whoamiCmd) rootCmd.AddCommand(uploadCmd) + rootCmd.AddCommand(rawCmd) } // version/build information command diff --git a/docs/commands/lagoon.md b/docs/commands/lagoon.md index 494a3dcd..8022f638 100644 --- a/docs/commands/lagoon.md +++ b/docs/commands/lagoon.md @@ -42,6 +42,7 @@ lagoon [flags] * [lagoon kibana](lagoon_kibana.md) - Launch the kibana interface * [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications * [lagoon login](lagoon_login.md) - Log into a Lagoon instance +* [lagoon raw](lagoon_raw.md) - Run a custom query or mutation * [lagoon retrieve](lagoon_retrieve.md) - Trigger a retrieval operation on backups * [lagoon run](lagoon_run.md) - Run a task against an environment * [lagoon ssh](lagoon_ssh.md) - Display the SSH command to access a specific environment in a project diff --git a/docs/commands/lagoon_raw.md b/docs/commands/lagoon_raw.md new file mode 100644 index 00000000..8b5c7bce --- /dev/null +++ b/docs/commands/lagoon_raw.md @@ -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 + diff --git a/mkdocs.yml b/mkdocs.yml index d1831340..fa9e1583 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,3 +47,4 @@ nav: - Getting Started: index.md - Configuration: config.md - Commands: commands/lagoon.md + - Custom Commands: customcommands.md