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
Commits
9333c504
Commit
9333c504
authored
10 years ago
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli,http: Make sure required file arguments are provided
parent
bc8a97c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
commands/cli/parse.go
commands/cli/parse.go
+7
-0
commands/http/parse.go
commands/http/parse.go
+9
-0
No files found.
commands/cli/parse.go
View file @
9333c504
...
...
@@ -248,6 +248,13 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
argDefIndex
++
}
// check to make sure we didn't miss any required arguments
for
_
,
argDef
:=
range
argDefs
[
argDefIndex
:
]
{
if
argDef
.
Required
{
return
nil
,
nil
,
fmt
.
Errorf
(
"Argument '%s' is required"
,
argDef
.
Name
)
}
}
return
stringArgs
,
fileArgs
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
commands/http/parse.go
View file @
9333c504
...
...
@@ -2,6 +2,7 @@ package http
import
(
"errors"
"fmt"
"mime"
"net/http"
"strings"
...
...
@@ -54,6 +55,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
args
:=
make
([]
string
,
valCount
)
valIndex
:=
0
requiredFile
:=
""
for
_
,
argDef
:=
range
cmd
.
Arguments
{
// skip optional argument definitions if there aren't sufficient remaining values
if
valCount
-
valIndex
<=
numRequired
&&
!
argDef
.
Required
{
...
...
@@ -78,6 +80,8 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
}
else
{
break
}
}
else
if
argDef
.
Type
==
cmds
.
ArgFile
&&
argDef
.
Required
&&
len
(
requiredFile
)
==
0
{
requiredFile
=
argDef
.
Name
}
}
...
...
@@ -101,6 +105,11 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
}
}
// if there is a required filearg, error if no files were provided
if
len
(
requiredFile
)
>
0
&&
f
==
nil
{
return
nil
,
fmt
.
Errorf
(
"File argument '%s' is required"
,
requiredFile
)
}
req
,
err
:=
cmds
.
NewRequest
(
path
,
opts
,
args
,
f
,
cmd
,
optDefs
)
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
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