Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
a6ef022d
Commit
a6ef022d
authored
Mar 21, 2019
by
jmank88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set WebFile fpath to URL base
parent
49cf8cee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
cli/parse.go
cli/parse.go
+18
-0
cli/parse_test.go
cli/parse_test.go
+19
-0
No files found.
cli/parse.go
View file @
a6ef022d
...
@@ -276,6 +276,17 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
...
@@ -276,6 +276,17 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return
err
return
err
}
}
}
else
if
u
:=
isURL
(
fpath
);
u
!=
nil
{
}
else
if
u
:=
isURL
(
fpath
);
u
!=
nil
{
base
:=
urlBase
(
u
)
fpath
=
base
if
_
,
ok
:=
fileArgs
[
fpath
];
ok
{
// Ensure a unique fpath by suffixing ' (n)'.
for
i
:=
1
;
;
i
++
{
fpath
=
fmt
.
Sprintf
(
"%s (%d)"
,
base
,
i
)
if
_
,
ok
:=
fileArgs
[
fpath
];
!
ok
{
break
}
}
}
file
=
files
.
NewWebFile
(
u
)
file
=
files
.
NewWebFile
(
u
)
}
else
{
}
else
{
fpath
=
filepath
.
ToSlash
(
filepath
.
Clean
(
fpath
))
fpath
=
filepath
.
ToSlash
(
filepath
.
Clean
(
fpath
))
...
@@ -363,6 +374,13 @@ func isURL(path string) *url.URL {
...
@@ -363,6 +374,13 @@ func isURL(path string) *url.URL {
}
}
}
}
func
urlBase
(
u
*
url
.
URL
)
string
{
if
u
.
Path
==
""
{
return
u
.
Host
}
return
path
.
Base
(
u
.
Path
)
}
func
splitkv
(
opt
string
)
(
k
,
v
string
,
ok
bool
)
{
func
splitkv
(
opt
string
)
(
k
,
v
string
,
ok
bool
)
{
split
:=
strings
.
SplitN
(
opt
,
"="
,
2
)
split
:=
strings
.
SplitN
(
opt
,
"="
,
2
)
if
len
(
split
)
==
2
{
if
len
(
split
)
==
2
{
...
...
cli/parse_test.go
View file @
a6ef022d
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"net/url"
"os"
"os"
"strings"
"strings"
"testing"
"testing"
...
@@ -534,3 +535,21 @@ func Test_isURL(t *testing.T) {
...
@@ -534,3 +535,21 @@ func Test_isURL(t *testing.T) {
}
}
}
}
}
}
func
Test_urlBase
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
[]
struct
{
url
,
base
string
}{
{
"http://host"
,
"host"
},
{
"http://host/test"
,
"test"
},
{
"http://host/test?param=val"
,
"test"
},
{
"http://host/test?param=val¶m2=val"
,
"test"
},
}
{
u
,
err
:=
url
.
Parse
(
test
.
url
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to parse %q: %v"
,
test
.
url
,
err
)
continue
}
if
got
:=
urlBase
(
u
);
got
!=
test
.
base
{
t
.
Errorf
(
"expected %q but got %q"
,
test
.
base
,
got
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment