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
722217d6
Commit
722217d6
authored
Nov 12, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli: Don't return root in Parse
parent
b6d98cfb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
9 deletions
+7
-9
cli/parse.go
cli/parse.go
+7
-9
No files found.
cli/parse.go
View file @
722217d6
...
...
@@ -15,38 +15,36 @@ var ErrInvalidSubcmd = errors.New("subcommand not found")
// Parse parses the input commandline string (cmd, flags, and args).
// returns the corresponding command Request object.
// Parse will search each root to find the one that best matches the requested subcommand.
// TODO: get rid of extraneous return values (e.g. we ended up not needing the root value anymore)
// TODO: get rid of multiple-root support, we should only need one now
func
Parse
(
input
[]
string
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
*
cmds
.
Command
,
*
cmds
.
Command
,
[]
string
,
error
)
{
func
Parse
(
input
[]
string
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
*
cmds
.
Command
,
[]
string
,
error
)
{
// use the root that matches the longest path (most accurately matches request)
path
,
input
,
cmd
:=
parsePath
(
input
,
root
)
opts
,
stringArgs
,
err
:=
parseOptions
(
input
)
if
err
!=
nil
{
return
nil
,
root
,
cmd
,
path
,
err
return
nil
,
cmd
,
path
,
err
}
if
len
(
path
)
==
0
{
return
nil
,
root
,
nil
,
path
,
ErrInvalidSubcmd
return
nil
,
nil
,
path
,
ErrInvalidSubcmd
}
args
,
err
:=
parseArgs
(
stringArgs
,
cmd
)
if
err
!=
nil
{
return
nil
,
root
,
cmd
,
path
,
err
return
nil
,
cmd
,
path
,
err
}
optDefs
,
err
:=
root
.
GetOptions
(
path
)
if
err
!=
nil
{
return
nil
,
root
,
cmd
,
path
,
err
return
nil
,
cmd
,
path
,
err
}
req
:=
cmds
.
NewRequest
(
path
,
opts
,
args
,
cmd
,
optDefs
)
err
=
cmd
.
CheckArguments
(
req
)
if
err
!=
nil
{
return
req
,
root
,
cmd
,
path
,
err
return
req
,
cmd
,
path
,
err
}
return
req
,
root
,
cmd
,
path
,
nil
return
req
,
cmd
,
path
,
nil
}
// parsePath separates the command path and the opts and args from a command string
...
...
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