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-unixfs
Commits
86bc450b
Commit
86bc450b
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli: Pass option definitions as an argument to parseOptions
parent
97b87190
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
9 deletions
+14
-9
commands/cli/parse.go
commands/cli/parse.go
+7
-7
commands/cli/parse_test.go
commands/cli/parse_test.go
+7
-2
No files found.
commands/cli/parse.go
View file @
86bc450b
...
...
@@ -13,7 +13,12 @@ func Parse(input []string, root *commands.Command) ([]string, []string, map[stri
return
nil
,
nil
,
nil
,
err
}
opts
,
args
,
err
:=
parseOptions
(
input
,
path
,
root
)
options
,
err
:=
root
.
GetOptions
(
path
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
err
}
opts
,
args
,
err
:=
parseOptions
(
input
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
err
}
...
...
@@ -44,12 +49,7 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro
// parseOptions parses the raw string values of the given options
// returns the parsed options as strings, along with the CLI args
func
parseOptions
(
input
,
path
[]
string
,
root
*
commands
.
Command
)
(
map
[
string
]
string
,
[]
string
,
error
)
{
options
,
err
:=
root
.
GetOptions
(
path
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
func
parseOptions
(
input
[]
string
,
options
map
[
string
]
commands
.
Option
)
(
map
[
string
]
string
,
[]
string
,
error
)
{
opts
:=
make
(
map
[
string
]
string
)
args
:=
make
([]
string
,
0
)
...
...
This diff is collapsed.
Click to expand it.
commands/cli/parse_test.go
View file @
86bc450b
...
...
@@ -15,8 +15,13 @@ func TestOptionParsing(t *testing.T) {
}
cmd
.
Register
(
"test"
,
&
commands
.
Command
{})
opts
,
input
,
err
:=
parseOptions
([]
string
{
"--beep"
,
"--boop=5 lol"
,
"test2"
,
"-cVb"
,
"beep"
},
[]
string
{
"test"
},
cmd
)
path
:=
[]
string
{
"test"
}
options
,
err
:=
cmd
.
GetOptions
(
path
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
opts
,
input
,
err
:=
parseOptions
([]
string
{
"--beep"
,
"--boop=5 lol"
,
"test2"
,
"-cVb"
,
"beep"
},
options
)
/*for k, v := range opts {
fmt.Printf("%s: %s\n", k, v)
}
...
...
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