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

Add new command to generate IntelliJ run configurations #48

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions cmd/idea.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cmd

import (
"fmt"
"github.com/Graylog2/graylog-project-cli/config"
"github.com/Graylog2/graylog-project-cli/idea"
"github.com/Graylog2/graylog-project-cli/manifest"
p "github.com/Graylog2/graylog-project-cli/project"
"github.com/Graylog2/graylog-project-cli/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var ideaCmd = &cobra.Command{
Expand All @@ -17,8 +20,9 @@ Commands to help working with the IntelliJ IDE.
}

var ideaSetupCmd = &cobra.Command{
Use: "setup",
Short: "Setup IntelliJ IDEA",
Deprecated: `use the "run-config create" command instead`,
Use: "setup",
Short: "Setup IntelliJ IDEA",
Long: `
This command will do the following:

Expand All @@ -30,8 +34,47 @@ This command will do the following:
Run: ideaSetupCommand,
}

var ideaRunConfigsCmd = &cobra.Command{
Use: "run-configs",
Aliases: []string{"rc"},
Short: "Manage IntelliJ IDEA run configurations",
}

var ideaRunConfigsCreateCmd = &cobra.Command{
Use: "create",
Aliases: []string{"c"},
Short: "Create IntelliJ IDEA run configurations",
Long: `This command adds default IntelliJ run configurations for Graylog Server,
Data Node, and the web development server.

The run configurations are created in the $PWD/.run/ directory.

Examples:
# Create default run configurations
graylog-project idea run-configs create

# Create default run configurations and .env files (requires installation of EnvFile plugin in IntelliJ)
graylog-project idea run-configs create -E

# Create run configurations for two Server and three Data Node instances
graylog-project idea run-configs create --instances server=2,data-node=3
`,
RunE: ideaRunConfigCreateCommand,
}

func init() {
ideaRunConfigsCreateCmd.Flags().BoolP("force", "f", false, "Overwrite existing run configurations")
ideaRunConfigsCreateCmd.Flags().BoolP("env-file", "E", false, "Use .env files (requires the IntelliJ EnvFile plugin)")
ideaRunConfigsCreateCmd.Flags().StringToIntP("instances", "i", idea.DefaultInstanceCounts, "Number of instances - example: server=1,data-node=3")
ideaRunConfigsCreateCmd.Flags().String("root-password", idea.DefaultRootPassword, "The root user password")
ideaRunConfigsCmd.AddCommand(ideaRunConfigsCreateCmd)

if err := viper.BindPFlags(ideaRunConfigsCreateCmd.Flags()); err != nil {
panic(err)
}

ideaCmd.AddCommand(ideaSetupCmd)
ideaCmd.AddCommand(ideaRunConfigsCmd)
RootCmd.AddCommand(ideaCmd)
}

Expand All @@ -41,3 +84,19 @@ func ideaSetupCommand(cmd *cobra.Command, args []string) {

idea.Setup(project)
}

func ideaRunConfigCreateCommand(cmd *cobra.Command, args []string) error {
var cfg idea.RunConfig
if err := viper.Unmarshal(&cfg); err != nil {
return fmt.Errorf("couldn't parse configuration: %w", err)
}

wd, err := utils.GetCwdE()
if err != nil {
return err
}

cfg.Workdir = wd

return idea.CreateRunConfigurations(cfg)
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ require (
github.com/fatih/color v1.18.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/go-github/v66 v66.0.0
github.com/google/renameio/v2 v2.0.0
github.com/hashicorp/go-version v1.7.0
github.com/imdario/mergo v0.3.16
github.com/k0kubun/pp/v3 v3.3.0
github.com/k0kubun/pp/v3 v3.4.1
github.com/manifoldco/promptui v0.9.0
github.com/mattn/go-isatty v0.0.20
github.com/pelletier/go-toml/v2 v2.2.3
Expand All @@ -20,10 +21,12 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/subosito/gotenv v1.6.0
github.com/yuin/goldmark v1.7.8
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/oauth2 v0.24.0
golang.org/x/text v0.20.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -45,12 +48,10 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// Workaround for https://github.com/golang/go/issues/30831
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/google/go-github/v66 v66.0.0 h1:ADJsaXj9UotwdgK8/iFZtv7MLc8E8WBl62WLd
github.com/google/go-github/v66 v66.0.0/go.mod h1:+4SO9Zkuyf8ytMj0csN1NR/5OTR+MfqPp8P8dVlcvY4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg=
github.com/google/renameio/v2 v2.0.0/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand All @@ -36,8 +38,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/k0kubun/pp/v3 v3.3.0 h1:/Unrck5tDGUSjsUJsmx9GUL64pNKOY5UEdoP1F7FBq8=
github.com/k0kubun/pp/v3 v3.3.0/go.mod h1:wJadGBvcY6JKaiUkB89VzUACKDmTX1r4aQTPERpZc6w=
github.com/k0kubun/pp/v3 v3.4.1 h1:1WdFZDRRqe8UsR61N/2RoOZ3ziTEqgTPVqKrHeb779Y=
github.com/k0kubun/pp/v3 v3.4.1/go.mod h1:+SiNiqKnBfw1Nkj82Lh5bIeKQOAkPy6Xw9CAZUZ8npI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
Loading