Skip to content

Commit 84f5f05

Browse files
authored
Updated flags definition in alpha module catalog (#2829)
1 parent 1bf7cb7 commit 84f5f05

File tree

5 files changed

+56
-107
lines changed

5 files changed

+56
-107
lines changed

docs/user/gen-docs/kyma_alpha_module_catalog.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,35 @@ kyma alpha module catalog [flags]
1414

1515
```bash
1616
# List all modules available in the cluster (core and community)
17-
kyma module catalog
17+
kyma alpha module catalog
1818

1919
# List available community modules from the official repository
20-
kyma module catalog --remote
20+
kyma alpha module catalog --remote
2121

2222
# List available community modules from a specific remote URL
23-
kyma module catalog --remote=https://example.com/modules.json
23+
kyma alpha module catalog --remote-url=https://example.com/modules.json
2424

2525
# List available community modules from multiple remote URLs
26-
kyma module catalog --remote=https://example.com/modules1.json,https://example.com/modules2.json
26+
kyma alpha module catalog --remote=https://example.com/modules1.json,https://example.com/modules2.json
2727

2828
# Output catalog as JSON
29-
kyma module catalog -o json
29+
kyma alpha module catalog -o json
3030

3131
# List remote community modules in YAML format
32-
kyma module catalog --remote -o yaml
32+
kyma alpha module catalog --remote -o yaml
3333
```
3434

3535
## Flags
3636

3737
```text
38-
-o, --output string Output format (Possible values: table, json, yaml)
39-
--remote bool or []string Fetch modules from the official repository or specify custom URL(s) (default "false")
40-
--context string The name of the kubeconfig context to use
41-
-h, --help Help for the command
42-
--kubeconfig string Path to the Kyma kubeconfig file
43-
--show-extensions-error Prints a possible error when fetching extensions fails
44-
--skip-extensions Skips fetching extensions from the target Kyma environment
38+
-o, --output string Output format (Possible values: table, json, yaml)
39+
--remote Fetch modules from the official repository
40+
--remote-url stringSlice List of URLs to custom community module repositories (default "[]")
41+
--context string The name of the kubeconfig context to use
42+
-h, --help Help for the command
43+
--kubeconfig string Path to the Kyma kubeconfig file
44+
--show-extensions-error Prints a possible error when fetching extensions fails
45+
--skip-extensions Skips fetching extensions from the target Kyma environment
4546
```
4647

4748
## See also

internal/cmd/alpha/module/catalog.go

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package module
22

33
import (
4-
"strings"
5-
64
"github.com/kyma-project/cli.v3/internal/clierror"
75
"github.com/kyma-project/cli.v3/internal/cmdcommon"
86
"github.com/kyma-project/cli.v3/internal/cmdcommon/types"
9-
"github.com/kyma-project/cli.v3/internal/flags"
107
"github.com/kyma-project/cli.v3/internal/modulesv2"
118
"github.com/kyma-project/cli.v3/internal/modulesv2/dtos"
129
"github.com/spf13/cobra"
@@ -15,7 +12,8 @@ import (
1512
type catalogConfig struct {
1613
*cmdcommon.KymaConfig
1714

18-
remote flags.BoolOrStrings
15+
remote bool
16+
remoteUrl []string
1917
outputFormat types.Format
2018
}
2119

@@ -29,42 +27,30 @@ func NewCatalogV2CMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command {
2927
Short: "Lists modules catalog",
3028
Long: `Use this command to list all available Kyma modules.`,
3129
Example: ` # List all modules available in the cluster (core and community)
32-
kyma module catalog
30+
kyma alpha module catalog
3331
3432
# List available community modules from the official repository
35-
kyma module catalog --remote
33+
kyma alpha module catalog --remote
3634
3735
# List available community modules from a specific remote URL
38-
kyma module catalog --remote=https://example.com/modules.json
36+
kyma alpha module catalog --remote-url=https://example.com/modules.json
3937
4038
# List available community modules from multiple remote URLs
41-
kyma module catalog --remote=https://example.com/modules1.json,https://example.com/modules2.json
39+
kyma alpha module catalog --remote=https://example.com/modules1.json,https://example.com/modules2.json
4240
4341
# Output catalog as JSON
44-
kyma module catalog -o json
42+
kyma alpha module catalog -o json
4543
4644
# List remote community modules in YAML format
47-
kyma module catalog --remote -o yaml`,
45+
kyma alpha module catalog --remote -o yaml`,
4846
Run: func(_ *cobra.Command, args []string) {
49-
if cfg.remote.Enabled && len(args) > 0 {
50-
for _, a := range args {
51-
parts := strings.SplitSeq(a, ",")
52-
for p := range parts {
53-
v := strings.TrimSpace(p)
54-
if v != "" {
55-
cfg.remote.Values = append(cfg.remote.Values, v)
56-
}
57-
}
58-
}
59-
}
6047
clierror.Check(catalogModules(&cfg))
6148
},
6249
}
6350

6451
cmd.Flags().VarP(&cfg.outputFormat, "output", "o", "Output format (Possible values: table, json, yaml)")
65-
66-
remoteFlag := cmd.Flags().VarPF(&cfg.remote, "remote", "", "Fetch modules from the official repository or specify custom URL(s)")
67-
remoteFlag.NoOptDefVal = "true"
52+
cmd.Flags().BoolVar(&cfg.remote, "remote", false, "Fetch modules from the official repository")
53+
cmd.Flags().StringSliceVar(&cfg.remoteUrl, "remote-url", []string{}, "List of URLs to custom community module repositories")
6854

6955
return cmd
7056
}
@@ -76,8 +62,7 @@ func catalogModules(cfg *catalogConfig) clierror.Error {
7662
if err != nil {
7763
return clierror.Wrap(err, clierror.New("failed to execute the catalog command"))
7864
}
79-
80-
catalogResult, err := catalogOperation.Run(cfg.Ctx, dtos.NewCatalogConfigFromRemote(cfg.remote))
65+
catalogResult, err := catalogOperation.Run(cfg.Ctx, dtos.NewCatalogConfigFromRemote(cfg.remote, cfg.remoteUrl))
8166
if err != nil {
8267
return clierror.Wrap(err, clierror.New("failed to list available modules from the target Kyma environment"))
8368
}

internal/flags/boolorstrings.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

internal/modulesv2/dtos/catalogconfig.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package dtos
22

3-
import (
4-
"github.com/kyma-project/cli.v3/internal/flags"
5-
)
6-
73
const KYMA_COMMUNITY_MODULES_REPOSITORY_URL = "https://kyma-project.github.io/community-modules/all-modules.json"
84

95
type CatalogConfig struct {
@@ -12,13 +8,19 @@ type CatalogConfig struct {
128
ExternalUrls []string
139
}
1410

15-
func NewCatalogConfigFromRemote(remote flags.BoolOrStrings) *CatalogConfig {
16-
if remote.Enabled && len(remote.Values) == 0 {
17-
return &CatalogConfig{ExternalUrls: []string{KYMA_COMMUNITY_MODULES_REPOSITORY_URL}}
11+
func NewCatalogConfigFromRemote(remote bool, remoteUrls []string) *CatalogConfig {
12+
externalUrls := []string{}
13+
14+
if remote {
15+
externalUrls = append(externalUrls, KYMA_COMMUNITY_MODULES_REPOSITORY_URL)
16+
}
17+
18+
if len(remoteUrls) > 0 {
19+
externalUrls = append(externalUrls, remoteUrls...)
1820
}
1921

20-
if remote.Enabled && len(remote.Values) > 0 {
21-
return &CatalogConfig{ExternalUrls: uniqueValues(remote.Values)}
22+
if len(externalUrls) > 0 {
23+
return &CatalogConfig{ExternalUrls: uniqueValues(externalUrls)}
2224
}
2325

2426
return &CatalogConfig{ListKyma: true, ListCluster: true}

internal/modulesv2/dtos/catalogconfig_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,55 @@ package dtos_test
33
import (
44
"testing"
55

6-
"github.com/kyma-project/cli.v3/internal/flags"
76
"github.com/kyma-project/cli.v3/internal/modulesv2/dtos"
87
"github.com/stretchr/testify/require"
98
)
109

1110
func Test_NewCatalogConfigFromRemote(t *testing.T) {
1211
tests := []struct {
13-
remote flags.BoolOrStrings
12+
remote bool
13+
remoteUrl []string
1414
expectedConfig dtos.CatalogConfig
1515
}{
1616
{
17-
remote: flags.BoolOrStrings{Enabled: false, Values: nil},
17+
remote: false,
18+
remoteUrl: nil,
1819
expectedConfig: dtos.CatalogConfig{ListKyma: true, ListCluster: true},
1920
},
2021
{
21-
remote: flags.BoolOrStrings{Enabled: false, Values: []string{}},
22+
remote: false,
23+
remoteUrl: []string{},
2224
expectedConfig: dtos.CatalogConfig{ListKyma: true, ListCluster: true},
2325
},
2426
{
25-
remote: flags.BoolOrStrings{Enabled: true, Values: nil},
27+
remote: true,
28+
remoteUrl: nil,
2629
expectedConfig: dtos.CatalogConfig{ExternalUrls: []string{dtos.KYMA_COMMUNITY_MODULES_REPOSITORY_URL}},
2730
},
2831
{
29-
remote: flags.BoolOrStrings{Enabled: true, Values: []string{}},
32+
remote: true,
33+
remoteUrl: []string{},
3034
expectedConfig: dtos.CatalogConfig{ExternalUrls: []string{dtos.KYMA_COMMUNITY_MODULES_REPOSITORY_URL}},
3135
},
3236
{
33-
remote: flags.BoolOrStrings{Enabled: true, Values: []string{"https://external-repo.co.uk", "https://example.com"}},
37+
remote: false,
38+
remoteUrl: []string{"https://external-repo.co.uk", "https://example.com"},
3439
expectedConfig: dtos.CatalogConfig{ExternalUrls: []string{"https://external-repo.co.uk", "https://example.com"}},
3540
},
3641
{
37-
remote: flags.BoolOrStrings{Enabled: true, Values: []string{"https://external-repo.co.uk", "https://example.com", "https://external-repo.co.uk", "https://external-repo.co.uk"}},
42+
remote: true,
43+
remoteUrl: []string{"https://external-repo.co.uk", "https://example.com"},
44+
expectedConfig: dtos.CatalogConfig{ExternalUrls: []string{dtos.KYMA_COMMUNITY_MODULES_REPOSITORY_URL, "https://external-repo.co.uk", "https://example.com"}},
45+
},
46+
{
47+
remote: false,
48+
remoteUrl: []string{"https://external-repo.co.uk", "https://example.com", "https://external-repo.co.uk", "https://external-repo.co.uk"},
3849
expectedConfig: dtos.CatalogConfig{ExternalUrls: []string{"https://external-repo.co.uk", "https://example.com"}},
3950
},
4051
}
4152

4253
for _, test := range tests {
43-
result := dtos.NewCatalogConfigFromRemote(test.remote)
54+
result := dtos.NewCatalogConfigFromRemote(test.remote, test.remoteUrl)
4455

4556
require.Equal(t, test.expectedConfig.ListKyma, result.ListKyma)
4657
require.Equal(t, test.expectedConfig.ListCluster, result.ListCluster)

0 commit comments

Comments
 (0)