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
3fc9bedb
Commit
3fc9bedb
authored
Jan 22, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Made Std{in|out|err} accessible in Request/Response
parent
b77d1c21
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
9 deletions
+34
-9
commands/request.go
commands/request.go
+9
-1
commands/response.go
commands/response.go
+20
-1
core/commands/add.go
core/commands/add.go
+4
-5
core/commands/cat.go
core/commands/cat.go
+1
-2
No files found.
commands/request.go
View file @
3fc9bedb
...
...
@@ -3,6 +3,8 @@ package commands
import
(
"errors"
"fmt"
"io"
"os"
"reflect"
"strconv"
...
...
@@ -78,6 +80,7 @@ type Request interface {
SetContext
(
Context
)
Command
()
*
Command
Values
()
map
[
string
]
interface
{}
Stdin
()
io
.
Reader
ConvertOptions
()
error
}
...
...
@@ -91,6 +94,7 @@ type request struct {
ctx
Context
optionDefs
map
[
string
]
Option
values
map
[
string
]
interface
{}
stdin
io
.
Reader
}
// Path returns the command path of this request
...
...
@@ -214,6 +218,10 @@ func (r *request) Values() map[string]interface{} {
return
r
.
values
}
func
(
r
*
request
)
Stdin
()
io
.
Reader
{
return
r
.
stdin
}
func
(
r
*
request
)
ConvertOptions
()
error
{
for
k
,
v
:=
range
r
.
options
{
opt
,
ok
:=
r
.
optionDefs
[
k
]
...
...
@@ -282,7 +290,7 @@ func NewRequest(path []string, opts optMap, args []string, file files.File, cmd
ctx
:=
Context
{
Context
:
context
.
TODO
()}
values
:=
make
(
map
[
string
]
interface
{})
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
ctx
,
optDefs
,
values
}
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
ctx
,
optDefs
,
values
,
os
.
Stdin
}
err
:=
req
.
ConvertOptions
()
if
err
!=
nil
{
return
nil
,
err
...
...
commands/response.go
View file @
3fc9bedb
...
...
@@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"io"
"os"
"strings"
)
...
...
@@ -105,6 +106,10 @@ type Response interface {
// Gets a io.Reader that reads the marshalled output
Reader
()
(
io
.
Reader
,
error
)
// Gets Stdout and Stderr, for writing to console without using SetOutput
Stdout
()
io
.
Writer
Stderr
()
io
.
Writer
}
type
response
struct
{
...
...
@@ -113,6 +118,8 @@ type response struct {
value
interface
{}
out
io
.
Reader
length
uint64
stdout
io
.
Writer
stderr
io
.
Writer
}
func
(
r
*
response
)
Request
()
Request
{
...
...
@@ -206,7 +213,19 @@ func (r *response) Reader() (io.Reader, error) {
return
r
.
out
,
nil
}
func
(
r
*
response
)
Stdout
()
io
.
Writer
{
return
r
.
stdout
}
func
(
r
*
response
)
Stderr
()
io
.
Writer
{
return
r
.
stderr
}
// NewResponse returns a response to match given Request
func
NewResponse
(
req
Request
)
Response
{
return
&
response
{
req
:
req
}
return
&
response
{
req
:
req
,
stdout
:
os
.
Stdout
,
stderr
:
os
.
Stderr
,
}
}
core/commands/add.go
View file @
3fc9bedb
...
...
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"os"
"path"
"strings"
...
...
@@ -139,7 +138,7 @@ remains to be implemented.
bar
.
Callback
=
func
(
line
string
)
{
terminalWidth
=
len
(
line
)
bar
.
Callback
=
nil
bar
.
Output
=
o
s
.
Stderr
bar
.
Output
=
re
s
.
Stderr
()
log
.
Infof
(
"terminal width: %v
\n
"
,
terminalWidth
)
}
bar
.
Update
()
...
...
@@ -153,12 +152,12 @@ remains to be implemented.
if
len
(
output
.
Hash
)
>
0
{
if
showProgressBar
{
// clear progress bar line before we print "added x" output
fmt
.
Fprintf
(
o
s
.
Stderr
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
fmt
.
Fprintf
(
re
s
.
Stderr
()
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
}
if
quiet
{
fmt
.
P
rintf
(
"%s
\n
"
,
output
.
Hash
)
fmt
.
Fp
rintf
(
res
.
Stdout
(),
"%s
\n
"
,
output
.
Hash
)
}
else
{
fmt
.
P
rintf
(
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
fmt
.
Fp
rintf
(
res
.
Stdout
(),
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
}
}
else
{
...
...
core/commands/cat.go
View file @
3fc9bedb
...
...
@@ -2,7 +2,6 @@ package commands
import
(
"io"
"os"
cmds
"github.com/jbenet/go-ipfs/commands"
core
"github.com/jbenet/go-ipfs/core"
...
...
@@ -51,7 +50,7 @@ it contains.
}
bar
:=
pb
.
New
(
int
(
res
.
Length
()))
.
SetUnits
(
pb
.
U_BYTES
)
bar
.
Output
=
o
s
.
Stderr
bar
.
Output
=
re
s
.
Stderr
()
bar
.
Start
()
reader
:=
bar
.
NewProxyReader
(
res
.
Output
()
.
(
io
.
Reader
))
...
...
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