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
827f1dd0
Commit
827f1dd0
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: Changed Request arguments to a []interface{}
parent
30e96875
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
20 deletions
+36
-20
commands/argument.go
commands/argument.go
+14
-0
commands/cli/parse.go
commands/cli/parse.go
+2
-2
commands/command.go
commands/command.go
+1
-0
commands/http/client.go
commands/http/client.go
+5
-2
commands/http/parse.go
commands/http/parse.go
+9
-11
commands/request.go
commands/request.go
+5
-5
No files found.
commands/argument.go
0 → 100644
View file @
827f1dd0
package
commands
type
ArgumentType
int
const
(
ArgString
ArgumentType
=
iota
ArgPath
)
type
Argument
struct
{
Name
string
Type
ArgumentType
Required
,
Variadic
bool
}
This diff is collapsed.
Click to expand it.
commands/cli/parse.go
View file @
827f1dd0
...
...
@@ -65,9 +65,9 @@ func parsePath(input []string, root *cmds.Command) ([]string, []string, *cmds.Co
// parseOptions parses the raw string values of the given options
// returns the parsed options as strings, along with the CLI args
func
parseOptions
(
input
[]
string
)
(
map
[
string
]
interface
{},
[]
string
,
error
)
{
func
parseOptions
(
input
[]
string
)
(
map
[
string
]
interface
{},
[]
interface
{}
,
error
)
{
opts
:=
make
(
map
[
string
]
interface
{})
args
:=
[]
string
{}
args
:=
[]
interface
{}
{}
for
i
:=
0
;
i
<
len
(
input
);
i
++
{
blob
:=
input
[
i
]
...
...
This diff is collapsed.
Click to expand it.
commands/command.go
View file @
827f1dd0
...
...
@@ -24,6 +24,7 @@ type Formatter func(Response) (string, error)
type
Command
struct
{
Help
string
Options
[]
Option
Arguments
[]
Argument
Run
Function
Format
Formatter
Type
interface
{}
...
...
This diff is collapsed.
Click to expand it.
commands/http/client.go
View file @
827f1dd0
...
...
@@ -44,8 +44,11 @@ func Send(req cmds.Request) (cmds.Response, error) {
for
k
,
v
:=
range
req
.
Options
()
{
query
+=
"&"
+
k
+
"="
+
v
.
(
string
)
}
for
_
,
v
:=
range
req
.
Arguments
()
{
query
+=
"&arg="
+
v
for
_
,
arg
:=
range
req
.
Arguments
()
{
s
,
ok
:=
arg
.
(
string
)
if
ok
{
query
+=
"&arg="
+
s
}
}
httpRes
,
err
:=
http
.
Post
(
url
+
query
,
"application/octet-stream"
,
req
.
Stream
())
...
...
This diff is collapsed.
Click to expand it.
commands/http/parse.go
View file @
827f1dd0
...
...
@@ -10,7 +10,7 @@ import (
// Parse parses the data in a http.Request and returns a command Request object
func
Parse
(
r
*
http
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
error
)
{
path
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)[
3
:
]
args
:=
make
([]
string
,
0
)
args
:=
make
([]
interface
{}
,
0
)
cmd
,
err
:=
root
.
Get
(
path
[
:
len
(
path
)
-
1
])
if
err
!=
nil
{
...
...
@@ -34,28 +34,26 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
opts
,
args2
:=
parseOptions
(
r
)
args
=
append
(
args
,
args2
...
)
// TODO: make a way to send opts/args in request body
// (e.g. if form-data or form-urlencoded, then treat the same as querystring)
// for now, to be simple, we just use the whole request body as the input stream
// (r.Body will be nil if there is no request body, like in GET requests)
in
:=
r
.
Body
return
cmds
.
NewRequest
(
path
,
opts
,
args
,
in
,
cmd
),
nil
return
cmds
.
NewRequest
(
path
,
opts
,
args
,
nil
,
cmd
),
nil
}
func
parseOptions
(
r
*
http
.
Request
)
(
map
[
string
]
interface
{},
[]
string
)
{
func
parseOptions
(
r
*
http
.
Request
)
(
map
[
string
]
interface
{},
[]
interface
{}
)
{
opts
:=
make
(
map
[
string
]
interface
{})
var
args
[]
string
args
:=
make
([]
interface
{},
0
)
query
:=
r
.
URL
.
Query
()
for
k
,
v
:=
range
query
{
if
k
==
"arg"
{
args
=
v
for
_
,
s
:=
range
v
{
args
=
append
(
args
,
interface
{}(
s
))
}
}
else
{
opts
[
k
]
=
v
[
0
]
}
}
// TODO: create multipart streams for file args
// default to setting encoding to JSON
_
,
short
:=
opts
[
cmds
.
EncShort
]
_
,
long
:=
opts
[
cmds
.
EncLong
]
...
...
This diff is collapsed.
Click to expand it.
commands/request.go
View file @
827f1dd0
...
...
@@ -24,7 +24,7 @@ type Request interface {
Option
(
name
string
)
(
interface
{},
bool
)
Options
()
map
[
string
]
interface
{}
SetOption
(
name
string
,
val
interface
{})
Arguments
()
[]
string
Arguments
()
[]
interface
{}
// TODO: make argument value type instead of using interface{}
Stream
()
io
.
Reader
SetStream
(
io
.
Reader
)
Context
()
*
Context
...
...
@@ -37,7 +37,7 @@ type Request interface {
type
request
struct
{
path
[]
string
options
optMap
arguments
[]
string
arguments
[]
interface
{}
in
io
.
Reader
cmd
*
Command
ctx
Context
...
...
@@ -69,7 +69,7 @@ func (r *request) SetOption(name string, val interface{}) {
}
// Arguments returns the arguments slice
func
(
r
*
request
)
Arguments
()
[]
string
{
func
(
r
*
request
)
Arguments
()
[]
interface
{}
{
return
r
.
arguments
}
...
...
@@ -165,7 +165,7 @@ func NewEmptyRequest() Request {
}
// NewRequest returns a request initialized with given arguments
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
string
,
in
io
.
Reader
,
cmd
*
Command
)
Request
{
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{}
,
in
io
.
Reader
,
cmd
*
Command
)
Request
{
if
path
==
nil
{
path
=
make
([]
string
,
0
)
}
...
...
@@ -173,7 +173,7 @@ func NewRequest(path []string, opts optMap, args []string, in io.Reader, cmd *Co
opts
=
make
(
map
[
string
]
interface
{})
}
if
args
==
nil
{
args
=
make
([]
string
,
0
)
args
=
make
([]
interface
{}
,
0
)
}
return
&
request
{
path
,
opts
,
args
,
in
,
cmd
,
Context
{}}
}
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