Skip to content

Commit 7c0d09d

Browse files
authored
Add new command to generate IntelliJ run configurations (#48)
* Add google/renameio/v2 dependency * Add new command to generate IntelliJ run configurations * Detect the OpenSearch version for the Data Node config * Use .template as template file suffix The regenerate command picks up all ".xml.tmpl" files in the repository and fails on the run configuration template. So we use a different suffix to avoid that issue. * Update dependencies * Warn users about hostname setup in /etc/hosts On Linux the *.localhost hostnames work automatically. On other operating systems the users have to add the names to /etc/hosts.
1 parent f2e55c4 commit 7c0d09d

28 files changed

+1767
-13
lines changed

cmd/idea.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"github.com/Graylog2/graylog-project-cli/config"
56
"github.com/Graylog2/graylog-project-cli/idea"
67
"github.com/Graylog2/graylog-project-cli/manifest"
78
p "github.com/Graylog2/graylog-project-cli/project"
9+
"github.com/Graylog2/graylog-project-cli/utils"
810
"github.com/spf13/cobra"
11+
"github.com/spf13/viper"
912
)
1013

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

1922
var ideaSetupCmd = &cobra.Command{
20-
Use: "setup",
21-
Short: "Setup IntelliJ IDEA",
23+
Deprecated: `use the "run-config create" command instead`,
24+
Use: "setup",
25+
Short: "Setup IntelliJ IDEA",
2226
Long: `
2327
This command will do the following:
2428
@@ -30,8 +34,47 @@ This command will do the following:
3034
Run: ideaSetupCommand,
3135
}
3236

37+
var ideaRunConfigsCmd = &cobra.Command{
38+
Use: "run-configs",
39+
Aliases: []string{"rc"},
40+
Short: "Manage IntelliJ IDEA run configurations",
41+
}
42+
43+
var ideaRunConfigsCreateCmd = &cobra.Command{
44+
Use: "create",
45+
Aliases: []string{"c"},
46+
Short: "Create IntelliJ IDEA run configurations",
47+
Long: `This command adds default IntelliJ run configurations for Graylog Server,
48+
Data Node, and the web development server.
49+
50+
The run configurations are created in the $PWD/.run/ directory.
51+
52+
Examples:
53+
# Create default run configurations
54+
graylog-project idea run-configs create
55+
56+
# Create default run configurations and .env files (requires installation of EnvFile plugin in IntelliJ)
57+
graylog-project idea run-configs create -E
58+
59+
# Create run configurations for two Server and three Data Node instances
60+
graylog-project idea run-configs create --instances server=2,data-node=3
61+
`,
62+
RunE: ideaRunConfigCreateCommand,
63+
}
64+
3365
func init() {
66+
ideaRunConfigsCreateCmd.Flags().BoolP("force", "f", false, "Overwrite existing run configurations")
67+
ideaRunConfigsCreateCmd.Flags().BoolP("env-file", "E", false, "Use .env files (requires the IntelliJ EnvFile plugin)")
68+
ideaRunConfigsCreateCmd.Flags().StringToIntP("instances", "i", idea.DefaultInstanceCounts, "Number of instances - example: server=1,data-node=3")
69+
ideaRunConfigsCreateCmd.Flags().String("root-password", idea.DefaultRootPassword, "The root user password")
70+
ideaRunConfigsCmd.AddCommand(ideaRunConfigsCreateCmd)
71+
72+
if err := viper.BindPFlags(ideaRunConfigsCreateCmd.Flags()); err != nil {
73+
panic(err)
74+
}
75+
3476
ideaCmd.AddCommand(ideaSetupCmd)
77+
ideaCmd.AddCommand(ideaRunConfigsCmd)
3578
RootCmd.AddCommand(ideaCmd)
3679
}
3780

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

4285
idea.Setup(project)
4386
}
87+
88+
func ideaRunConfigCreateCommand(cmd *cobra.Command, args []string) error {
89+
var cfg idea.RunConfig
90+
if err := viper.Unmarshal(&cfg); err != nil {
91+
return fmt.Errorf("couldn't parse configuration: %w", err)
92+
}
93+
94+
wd, err := utils.GetCwdE()
95+
if err != nil {
96+
return err
97+
}
98+
99+
cfg.Workdir = wd
100+
101+
return idea.CreateRunConfigurations(cfg)
102+
}

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ require (
88
github.com/fatih/color v1.18.0
99
github.com/golang-jwt/jwt/v5 v5.2.1
1010
github.com/google/go-github/v66 v66.0.0
11+
github.com/google/renameio/v2 v2.0.0
1112
github.com/hashicorp/go-version v1.7.0
1213
github.com/imdario/mergo v0.3.16
13-
github.com/k0kubun/pp/v3 v3.3.0
14+
github.com/k0kubun/pp/v3 v3.4.1
1415
github.com/manifoldco/promptui v0.9.0
1516
github.com/mattn/go-isatty v0.0.20
1617
github.com/pelletier/go-toml/v2 v2.2.3
@@ -20,10 +21,12 @@ require (
2021
github.com/spf13/cobra v1.8.1
2122
github.com/spf13/viper v1.19.0
2223
github.com/stretchr/testify v1.9.0
24+
github.com/subosito/gotenv v1.6.0
2325
github.com/yuin/goldmark v1.7.8
2426
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
2527
golang.org/x/oauth2 v0.24.0
2628
golang.org/x/text v0.20.0
29+
gopkg.in/yaml.v3 v3.0.1
2730
)
2831

2932
require (
@@ -45,12 +48,10 @@ require (
4548
github.com/spf13/afero v1.11.0 // indirect
4649
github.com/spf13/cast v1.7.0 // indirect
4750
github.com/spf13/pflag v1.0.5 // indirect
48-
github.com/subosito/gotenv v1.6.0 // indirect
4951
go.uber.org/multierr v1.11.0 // indirect
5052
golang.org/x/sys v0.27.0 // indirect
5153
golang.org/x/term v0.26.0 // indirect
5254
gopkg.in/ini.v1 v1.67.0 // indirect
53-
gopkg.in/yaml.v3 v3.0.1 // indirect
5455
)
5556

5657
// Workaround for https://github.com/golang/go/issues/30831

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/google/go-github/v66 v66.0.0 h1:ADJsaXj9UotwdgK8/iFZtv7MLc8E8WBl62WLd
2828
github.com/google/go-github/v66 v66.0.0/go.mod h1:+4SO9Zkuyf8ytMj0csN1NR/5OTR+MfqPp8P8dVlcvY4=
2929
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
3030
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
31+
github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg=
32+
github.com/google/renameio/v2 v2.0.0/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4=
3133
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
3234
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
3335
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
@@ -36,8 +38,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
3638
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
3739
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3840
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
39-
github.com/k0kubun/pp/v3 v3.3.0 h1:/Unrck5tDGUSjsUJsmx9GUL64pNKOY5UEdoP1F7FBq8=
40-
github.com/k0kubun/pp/v3 v3.3.0/go.mod h1:wJadGBvcY6JKaiUkB89VzUACKDmTX1r4aQTPERpZc6w=
41+
github.com/k0kubun/pp/v3 v3.4.1 h1:1WdFZDRRqe8UsR61N/2RoOZ3ziTEqgTPVqKrHeb779Y=
42+
github.com/k0kubun/pp/v3 v3.4.1/go.mod h1:+SiNiqKnBfw1Nkj82Lh5bIeKQOAkPy6Xw9CAZUZ8npI=
4143
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
4244
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
4345
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

0 commit comments

Comments
 (0)