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
1c8d73f9
Commit
1c8d73f9
authored
Nov 16, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Added Request#Files()
parent
fdb71eb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
21 deletions
+11
-21
commands/request.go
commands/request.go
+11
-21
No files found.
commands/request.go
View file @
1c8d73f9
...
@@ -3,7 +3,6 @@ package commands
...
@@ -3,7 +3,6 @@ package commands
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
"reflect"
"reflect"
"strconv"
"strconv"
...
@@ -62,13 +61,8 @@ type Request interface {
...
@@ -62,13 +61,8 @@ type Request interface {
Option
(
name
string
)
*
OptionValue
Option
(
name
string
)
*
OptionValue
Options
()
optMap
Options
()
optMap
SetOption
(
name
string
,
val
interface
{})
SetOption
(
name
string
,
val
interface
{})
Arguments
()
[]
interface
{}
// Arguments() returns user provided arguments as declared on the Command.
Files
()
File
//
// NB: `io.Reader`s returned by Arguments() are owned by the library.
// Readers are not guaranteed to remain open after the Command's Run
// function returns.
Arguments
()
[]
interface
{}
// TODO: make argument value type instead of using interface{}
Context
()
*
Context
Context
()
*
Context
SetContext
(
Context
)
SetContext
(
Context
)
Command
()
*
Command
Command
()
*
Command
...
@@ -81,6 +75,7 @@ type request struct {
...
@@ -81,6 +75,7 @@ type request struct {
path
[]
string
path
[]
string
options
optMap
options
optMap
arguments
[]
interface
{}
arguments
[]
interface
{}
files
File
cmd
*
Command
cmd
*
Command
ctx
Context
ctx
Context
optionDefs
map
[
string
]
Option
optionDefs
map
[
string
]
Option
...
@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
...
@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
return
r
.
arguments
return
r
.
arguments
}
}
func
(
r
*
request
)
Files
()
File
{
return
r
.
files
}
func
(
r
*
request
)
Context
()
*
Context
{
func
(
r
*
request
)
Context
()
*
Context
{
return
&
r
.
ctx
return
&
r
.
ctx
}
}
...
@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
...
@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
}
}
func
(
r
*
request
)
Cleanup
()
error
{
func
(
r
*
request
)
Cleanup
()
error
{
for
_
,
arg
:=
range
r
.
arguments
{
// TODO
closer
,
ok
:=
arg
.
(
io
.
Closer
)
if
ok
{
err
:=
closer
.
Close
()
if
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
}
}
...
@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
...
@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
// NewEmptyRequest initializes an empty request
// NewEmptyRequest initializes an empty request
func
NewEmptyRequest
()
(
Request
,
error
)
{
func
NewEmptyRequest
()
(
Request
,
error
)
{
return
NewRequest
(
nil
,
nil
,
nil
,
nil
,
nil
)
return
NewRequest
(
nil
,
nil
,
nil
,
nil
,
nil
,
nil
)
}
}
// NewRequest returns a request initialized with given arguments
// NewRequest returns a request initialized with given arguments
// An non-nil error will be returned if the provided option values are invalid
// An non-nil error will be returned if the provided option values are invalid
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{},
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{},
file
File
,
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
if
path
==
nil
{
if
path
==
nil
{
path
=
make
([]
string
,
0
)
path
=
make
([]
string
,
0
)
}
}
...
@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
...
@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
optDefs
=
make
(
map
[
string
]
Option
)
optDefs
=
make
(
map
[
string
]
Option
)
}
}
req
:=
&
request
{
path
,
opts
,
args
,
cmd
,
Context
{},
optDefs
}
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
Context
{},
optDefs
}
err
:=
req
.
ConvertOptions
()
err
:=
req
.
ConvertOptions
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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