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
3f603079
Commit
3f603079
authored
Oct 31, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 04, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli: Made Parse handle multiple root commands
parent
8ce67522
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
cli/parse.go
cli/parse.go
+20
-6
No files found.
cli/parse.go
View file @
3f603079
...
...
@@ -9,17 +9,31 @@ import (
// Parse parses the input commandline string (cmd, flags, and args).
// returns the corresponding command Request object.
func
Parse
(
input
[]
string
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
error
)
{
path
,
input
,
cmd
:=
parsePath
(
input
,
root
)
opts
,
args
,
err
:=
parseOptions
(
input
)
if
err
!=
nil
{
return
nil
,
err
func
Parse
(
input
[]
string
,
roots
...*
cmds
.
Command
)
(
cmds
.
Request
,
*
cmds
.
Command
,
error
)
{
var
req
cmds
.
Request
var
root
*
cmds
.
Command
// use the root that matches the longest path (most accurately matches request)
maxLength
:=
0
for
_
,
r
:=
range
roots
{
path
,
input
,
cmd
:=
parsePath
(
input
,
r
)
opts
,
args
,
err
:=
parseOptions
(
input
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
length
:=
len
(
path
)
if
length
>
maxLength
{
maxLength
=
length
req
=
cmds
.
NewRequest
(
path
,
opts
,
args
,
nil
,
cmd
)
root
=
r
}
}
// TODO: figure out how to know when to read given file(s) as an input stream
// (instead of filename arg string)
return
cmds
.
NewRequest
(
path
,
opts
,
args
,
nil
,
cmd
)
,
nil
return
req
,
root
,
nil
}
// parsePath gets the command path from the command line input
...
...
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