Skip to content

Commit 3db2326

Browse files
committed
Fix IDE CLI commands: clean help output, hide legacy aliases, and ensure modular command registration
1 parent 4d44b8a commit 3db2326

File tree

6 files changed

+64
-42
lines changed

6 files changed

+64
-42
lines changed

artifactory/cli/ide/jetbrains/cli.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/jfrog/gofrog/log"
99
"github.com/jfrog/jfrog-cli-artifactory/artifactory/cli/ide"
1010
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/ide/jetbrains"
11-
"github.com/jfrog/jfrog-cli-artifactory/cliutils"
1211
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
1312
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
1413
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -78,10 +77,10 @@ func jetbrainsConfigCmd(c *components.Context) error {
7877
}
7978

8079
// getJetbrainsRepoKeyAndURL determines the repo key and repository URL from args/flags
81-
func getJetbrainsRepoKeyAndURL(c *components.Context) (repositoryURL, repoKey string, err error) {
80+
func getJetbrainsRepoKeyAndURL(c *components.Context) (repoKey, repositoryURL string, err error) {
8281
if c.GetNumberOfArgs() > 0 && isValidUrl(c.GetArgumentAt(0)) {
8382
repositoryURL = c.GetArgumentAt(0)
84-
repoKey, err = cliutils.ExtractRepoNameFromURL(repositoryURL)
83+
repoKey, err = extractRepoKeyFromRepositoryURL(repositoryURL)
8584
if err != nil {
8685
return
8786
}
@@ -117,6 +116,23 @@ func getJetbrainsRepoKeyAndURL(c *components.Context) (repositoryURL, repoKey st
117116
return
118117
}
119118

119+
// extractRepoKeyFromRepositoryURL extracts the repo key from a JetBrains plugins repository URL.
120+
func extractRepoKeyFromRepositoryURL(repositoryURL string) (string, error) {
121+
if repositoryURL == "" {
122+
return "", fmt.Errorf("repository URL is empty")
123+
}
124+
trimmed := strings.TrimSuffix(repositoryURL, "/")
125+
parts := strings.Split(trimmed, "/api/jetbrainsplugins/")
126+
if len(parts) != 2 {
127+
return "", fmt.Errorf("repository URL does not contain /api/jetbrainsplugins/")
128+
}
129+
pathParts := strings.SplitN(parts[1], "/", 2)
130+
if len(pathParts) == 0 || pathParts[0] == "" {
131+
return "", fmt.Errorf("repository key not found in repository URL")
132+
}
133+
return pathParts[0], nil
134+
}
135+
120136
// getJetbrainsServerDetails returns server details for validation, or nil if not available
121137
func getJetbrainsServerDetails(c *components.Context) (*config.ServerDetails, error) {
122138
if ide.HasServerConfigFlags(c) {

artifactory/cli/ide/vscode/cli.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/jfrog/gofrog/log"
99
"github.com/jfrog/jfrog-cli-artifactory/artifactory/cli/ide"
1010
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/ide/vscode"
11-
"github.com/jfrog/jfrog-cli-artifactory/cliutils"
1211
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
1312
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
1413
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -61,7 +60,7 @@ func getArguments() []components.Argument {
6160

6261
// Main command action: orchestrates argument parsing, server config, and command execution
6362
func vscodeConfigCmd(c *components.Context) error {
64-
serviceURL, repoKey, err := getVscodeRepoKeyAndURL(c)
63+
repoKey, serviceURL, err := getVscodeRepoKeyAndURL(c)
6564
if err != nil {
6665
return err
6766
}
@@ -73,7 +72,7 @@ func vscodeConfigCmd(c *components.Context) error {
7372
return err
7473
}
7574

76-
vscodeCmd := vscode.NewVscodeCommand(serviceURL, productPath, repoKey)
75+
vscodeCmd := vscode.NewVscodeCommand(repoKey, productPath, serviceURL)
7776
if rtDetails != nil {
7877
vscodeCmd.SetServerDetails(rtDetails)
7978
}
@@ -82,13 +81,15 @@ func vscodeConfigCmd(c *components.Context) error {
8281
}
8382

8483
// getVscodeRepoKeyAndURL determines the repo key and service URL from args/flags
85-
func getVscodeRepoKeyAndURL(c *components.Context) (serviceURL, repoKey string, err error) {
84+
func getVscodeRepoKeyAndURL(c *components.Context) (repoKey, serviceURL string, err error) {
8685
if c.GetNumberOfArgs() > 0 && isValidUrl(c.GetArgumentAt(0)) {
8786
serviceURL = c.GetArgumentAt(0)
88-
repoKey, err = cliutils.ExtractRepoNameFromURL(serviceURL)
87+
repoKey, err = extractRepoKeyFromServiceURL(serviceURL)
8988
if err != nil {
9089
return
9190
}
91+
log.Info("[DEBUG] Extracted repoKey:", repoKey)
92+
log.Info("[DEBUG] Service URL:", serviceURL)
9293
return
9394
}
9495

@@ -121,6 +122,23 @@ func getVscodeRepoKeyAndURL(c *components.Context) (serviceURL, repoKey string,
121122
return
122123
}
123124

125+
// extractRepoKeyFromServiceURL extracts the repo key from a VSCode extensions service URL.
126+
func extractRepoKeyFromServiceURL(serviceURL string) (string, error) {
127+
if serviceURL == "" {
128+
return "", fmt.Errorf("service URL is empty")
129+
}
130+
trimmed := strings.TrimSuffix(serviceURL, "/")
131+
parts := strings.Split(trimmed, "/api/vscodeextensions/")
132+
if len(parts) != 2 {
133+
return "", fmt.Errorf("service URL does not contain /api/vscodeextensions/")
134+
}
135+
pathParts := strings.SplitN(parts[1], "/", 2)
136+
if len(pathParts) == 0 || pathParts[0] == "" {
137+
return "", fmt.Errorf("repository key not found in service URL")
138+
}
139+
return pathParts[0], nil
140+
}
141+
124142
// getVscodeServerDetails returns server details for validation, or nil if not available
125143
func getVscodeServerDetails(c *components.Context) (*config.ServerDetails, error) {
126144
if ide.HasServerConfigFlags(c) {

artifactory/commands/ide/vscode/vscode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ type VscodeCommand struct {
2828
}
2929

3030
// NewVscodeCommand creates a new VSCode configuration command
31-
func NewVscodeCommand(serviceURL, productPath, repoKey string) *VscodeCommand {
31+
func NewVscodeCommand(repoKey, productPath, serviceURL string) *VscodeCommand {
3232
return &VscodeCommand{
33-
serviceURL: serviceURL,
34-
productPath: productPath,
3533
repoKey: repoKey,
34+
productPath: productPath,
35+
serviceURL: serviceURL,
3636
}
3737
}
3838

artifactory/commands/npm/npmpublish.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
buildinfo "github.com/jfrog/build-info-go/entities"
99
gofrogcmd "github.com/jfrog/gofrog/io"
10-
"github.com/jfrog/jfrog-cli-artifactory/cliutils"
1110
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1211
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
1312
"github.com/jfrog/jfrog-client-go/artifactory/services"
@@ -31,7 +30,7 @@ func (npu *npmPublish) upload() (err error) {
3130
if err != nil {
3231
return err
3332
}
34-
targetRepo, err = cliutils.ExtractRepoNameFromURL(repoConfig)
33+
targetRepo, err = extractRepoName(repoConfig)
3534
if err != nil {
3635
return err
3736
}
@@ -125,6 +124,21 @@ func (npu *NpmPublishCommand) getRepoConfig() (string, error) {
125124
return repoConfig, nil
126125
}
127126

127+
func extractRepoName(configUrl string) (string, error) {
128+
url := strings.TrimSpace(configUrl)
129+
url = strings.TrimPrefix(url, "https://")
130+
url = strings.TrimPrefix(url, "http://")
131+
url = strings.TrimSuffix(url, "/")
132+
if url == "" {
133+
return "", errors.New("npm config URL is empty")
134+
}
135+
urlParts := strings.Split(url, "/")
136+
if len(urlParts) < 2 {
137+
return "", errors.New("npm config URL is not valid")
138+
}
139+
return urlParts[len(urlParts)-1], nil
140+
}
141+
128142
func extractConfigServer(configUrl string) (*config.ServerDetails, error) {
129143
var requiredServerDetails = &config.ServerDetails{}
130144
url := strings.TrimSpace(configUrl)

artifactory/commands/npm/npmpublish_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package npm
33

44
import (
55
"testing"
6-
7-
"github.com/jfrog/jfrog-cli-artifactory/cliutils"
86
)
97

108
func TestExtractRepoName(t *testing.T) {
@@ -48,13 +46,13 @@ func TestExtractRepoName(t *testing.T) {
4846

4947
for _, tt := range tests {
5048
t.Run(tt.name, func(t *testing.T) {
51-
result, err := cliutils.ExtractRepoNameFromURL(tt.input)
49+
result, err := extractRepoName(tt.input)
5250
if (err != nil) != tt.expectError {
53-
t.Errorf("ExtractRepoNameFromURL(%q) error = %v, expectError %v", tt.input, err, tt.expectError)
51+
t.Errorf("extractRepoName(%q) error = %v, expectError %v", tt.input, err, tt.expectError)
5452
return
5553
}
5654
if !tt.expectError && result != tt.expected {
57-
t.Errorf("ExtractRepoNameFromURL(%q) = %q; want %q", tt.input, result, tt.expected)
55+
t.Errorf("extractRepoName(%q) = %q; want %q", tt.input, result, tt.expected)
5856
}
5957
})
6058
}

cliutils/repo.go

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

0 commit comments

Comments
 (0)