Skip to content

Commit 78c4be8

Browse files
committed
revert changes for parsing the curl cmd arg
1 parent cff377f commit 78c4be8

File tree

2 files changed

+2
-46
lines changed

2 files changed

+2
-46
lines changed

common/commands/curl.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,34 +146,18 @@ func (curlCmd *CurlCommand) GetServerDetails() (*config.ServerDetails, error) {
146146
// Use this method ONLY after removing all JFrog-CLI flags, i.e. flags in the form: '--my-flag=value' are not allowed.
147147
// An argument is any provided candidate which is not a flag or a flag value.
148148
func (curlCmd *CurlCommand) findUriValueAndIndex() (int, string) {
149-
cntArgs := 0
150-
for range curlCmd.arguments {
151-
cntArgs++
152-
}
153-
154149
skipThisArg := false
155150
for index, arg := range curlCmd.arguments {
156-
if skipThisArg && !strings.HasPrefix(arg, "-") && index == cntArgs-1 {
157-
return index, arg
158-
}
159-
160151
// Check if shouldn't check current arg.
161-
if skipThisArg && !strings.HasPrefix(arg, "-") {
152+
if skipThisArg {
162153
skipThisArg = false
163154
continue
164155
}
165-
166-
// If we were expecting a value but found a flag instead, reset skipThisArg
167-
if skipThisArg && strings.HasPrefix(arg, "-") {
168-
skipThisArg = false
169-
}
170-
171156
// If starts with '--', meaning a flag which its value is at next slot.
172157
if strings.HasPrefix(arg, "--") {
173158
skipThisArg = true
174159
continue
175160
}
176-
177161
// Check if '-'.
178162
if strings.HasPrefix(arg, "-") {
179163
if len(arg) > 2 {

common/commands/curl_test.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ func TestFindNextArg(t *testing.T) {
1010
{"-X", "GET", "arg1", "--foo", "bar"},
1111
{"-X", "GET", "--server-idea", "foo", "/api/arg2"},
1212
{"-XGET", "--foo", "bar", "--foo-bar", "meow", "arg3"},
13-
{"-o", "helm.tar.gz", "-L", "-vvv", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
14-
{"-o", "helm.tar.gz", "-vvv", "-L", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
15-
{"-o", "helm.tar.gz", "-L", "-s", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
16-
{"-L", "-o", "helm.tar.gz", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
17-
{"-o", "helm.tar.gz", "-L", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
18-
{"-L", "-vvv", "-o", "helm.tar.gz", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
19-
{"-L", "-o", "helm.tar.gz", "-vvv", "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
20-
{"-vvv", "-s", "-L", "api/test"},
21-
{"-LsS", "api/test2"},
22-
{"-ofile.txt", "-L", "api/test3"},
2313
}
2414

2515
expected := []struct {
@@ -29,24 +19,6 @@ func TestFindNextArg(t *testing.T) {
2919
{2, "arg1"},
3020
{4, "/api/arg2"},
3121
{5, "arg3"},
32-
{4, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
33-
{4, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
34-
{4, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
35-
{3, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
36-
{3, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
37-
{4, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
38-
{4, "helm-sh/helm-v3.19.0-linux-amd64.tar.gz"},
39-
{3, "api/test"},
40-
{1, "api/test2"},
41-
{2, "api/test3"},
42-
{-1, ""},
43-
{4, "api/endpoint"},
44-
{0, "api/endpoint"},
45-
{2, "api/endpoint"},
46-
{2, "api/endpoint"},
47-
{-1, ""},
48-
{-1, ""},
49-
{-1, ""},
5022
}
5123

5224
for index, test := range args {
@@ -99,7 +71,7 @@ func TestBuildCommandUrl(t *testing.T) {
9971
{"test1", []string{"-X", "GET", "/api/build/test1", "--server-id", "test1", "--foo", "bar"}, 2, "https://artifactory:8081/artifactory/api/build/test1", false},
10072
{"test2", []string{"-X", "GET", "/api/build/test2", "--server-idea", "foo", "--server-id=test2"}, 2, "https://artifactory:8081/artifactory/api/build/test2", false},
10173
{"test3", []string{"-XGET", "--/api/build/test3", "--server-id="}, 1, "https://artifactory:8081/artifactory/api/build/test3", true},
102-
{"test4", []string{"-XGET", "-Test4", "--server-id", "bar"}, 3, "https://artifactory:8081/artifactory/bar", false},
74+
{"test4", []string{"-XGET", "-Test4", "--server-id", "bar"}, 1, "https://artifactory:8081/artifactory/api/build/test4", true},
10375
{"test5", []string{"-X", "GET", "api/build/test5", "--server-id", "test5", "--foo", "bar"}, 2, "https://artifactory:8081/artifactory/api/build/test5", false},
10476
}
10577

0 commit comments

Comments
 (0)