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
4ca651ae
Unverified
Commit
4ca651ae
authored
Mar 21, 2019
by
Steven Allen
Committed by
GitHub
Mar 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #154 from jmank88/webfile
support url paths as files.WebFile
parents
3c3985a5
cd8ef8fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
cli/parse.go
cli/parse.go
+20
-0
cli/parse_test.go
cli/parse_test.go
+21
-0
No files found.
cli/parse.go
View file @
4ca651ae
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net/url"
"os"
"path"
"path/filepath"
...
...
@@ -269,6 +270,8 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
if
err
!=
nil
{
return
err
}
}
else
if
u
:=
isURL
(
fpath
);
u
!=
nil
{
file
=
files
.
NewWebFile
(
u
)
}
else
{
fpath
=
filepath
.
ToSlash
(
filepath
.
Clean
(
fpath
))
derefArgs
,
_
:=
req
.
Options
[
cmds
.
DerefLong
]
.
(
bool
)
...
...
@@ -338,6 +341,23 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
return
nil
}
// isURL returns a url.URL for valid http:// and https:// URLs, otherwise it returns nil.
func
isURL
(
path
string
)
*
url
.
URL
{
u
,
err
:=
url
.
Parse
(
path
)
if
err
!=
nil
{
return
nil
}
if
u
.
Host
==
""
{
return
nil
}
switch
u
.
Scheme
{
default
:
return
nil
case
"http"
,
"https"
:
return
u
}
}
func
splitkv
(
opt
string
)
(
k
,
v
string
,
ok
bool
)
{
split
:=
strings
.
SplitN
(
opt
,
"="
,
2
)
if
len
(
split
)
==
2
{
...
...
cli/parse_test.go
View file @
4ca651ae
...
...
@@ -513,3 +513,24 @@ func TestBodyArgs(t *testing.T) {
}
}
}
func
Test_isURL
(
t
*
testing
.
T
)
{
for
_
,
u
:=
range
[]
string
{
"http://www.example.com"
,
"https://www.example.com"
,
}
{
if
isURL
(
u
)
==
nil
{
t
.
Errorf
(
"expected url: %s"
,
u
)
}
}
for
_
,
u
:=
range
[]
string
{
"adir/afile"
,
"http:/ /afile"
,
"http:/a/file"
,
}
{
if
isURL
(
u
)
!=
nil
{
t
.
Errorf
(
"expected non-url: %s"
,
u
)
}
}
}
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