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
f3b5b7b4
Commit
f3b5b7b4
authored
Oct 13, 2017
by
keks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fmt
parent
ccd0b22b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
examples/adder/cmd.go
examples/adder/cmd.go
+14
-14
examples/adder/local/main.go
examples/adder/local/main.go
+4
-4
examples/adder/remote/client/main.go
examples/adder/remote/client/main.go
+1
-1
No files found.
examples/adder/cmd.go
View file @
f3b5b7b4
...
...
@@ -16,7 +16,7 @@ import (
type
AddStatus
struct
{
// Current is the current value of the sum.
Current
int
// Left is how many summands are left
Left
int
}
...
...
@@ -64,7 +64,7 @@ var RootCmd = &cmds.Command{
sum
+=
num
re
.
Emit
(
&
AddStatus
{
Current
:
sum
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
})
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
...
...
@@ -77,13 +77,13 @@ var RootCmd = &cmds.Command{
if
!
ok
{
return
fmt
.
Errorf
(
"cast error, got type %T"
,
v
)
}
if
s
.
Left
==
0
{
fmt
.
Fprintln
(
w
,
"total:"
,
s
.
Current
)
}
else
{
fmt
.
Fprintf
(
w
,
"intermediate result: %d; %d left
\n
"
,
s
.
Current
,
s
.
Left
)
}
return
nil
}),
},
...
...
@@ -107,7 +107,7 @@ var RootCmd = &cmds.Command{
sum
+=
num
re
.
Emit
(
&
AddStatus
{
Current
:
sum
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
})
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
...
...
@@ -116,14 +116,14 @@ var RootCmd = &cmds.Command{
PostRun
:
cmds
.
PostRunMap
{
cmds
.
CLI
:
func
(
req
cmds
.
Request
,
re
cmds
.
ResponseEmitter
)
cmds
.
ResponseEmitter
{
reNext
,
res
:=
cmds
.
NewChanResponsePair
(
req
)
go
func
()
{
defer
re
.
Close
()
defer
fmt
.
Println
()
// length of line at last iteration
var
lastLen
int
for
{
v
,
err
:=
res
.
Next
()
if
err
==
io
.
EOF
{
...
...
@@ -148,7 +148,7 @@ var RootCmd = &cmds.Command{
}
}
}()
return
reNext
},
},
...
...
@@ -172,7 +172,7 @@ var RootCmd = &cmds.Command{
sum
+=
num
re
.
Emit
(
&
AddStatus
{
Current
:
sum
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
Left
:
len
(
req
.
Arguments
())
-
i
-
1
,
})
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
...
...
@@ -182,14 +182,14 @@ var RootCmd = &cmds.Command{
cmds
.
CLI
:
func
(
req
cmds
.
Request
,
re
cmds
.
ResponseEmitter
)
cmds
.
ResponseEmitter
{
reNext
,
res
:=
cmds
.
NewChanResponsePair
(
req
)
clire
:=
re
.
(
cli
.
ResponseEmitter
)
go
func
()
{
defer
re
.
Close
()
defer
fmt
.
Println
()
// length of line at last iteration
var
lastLen
int
var
exit
int
defer
func
()
{
clire
.
Exit
(
exit
)
...
...
@@ -221,7 +221,7 @@ var RootCmd = &cmds.Command{
}
}()
return
reNext
},
},
...
...
examples/adder/local/main.go
View file @
f3b5b7b4
...
...
@@ -5,8 +5,8 @@ import (
"github.com/ipfs/go-ipfs-cmds/examples/adder"
"gx/ipfs/QmPhtZyjPYddJ8yGPWreisp47H6iQjt3Lg8sZrzqMP5noy/go-ipfs-cmds/cli"
"gx/ipfs/QmPhtZyjPYddJ8yGPWreisp47H6iQjt3Lg8sZrzqMP5noy/go-ipfs-cmds"
"gx/ipfs/QmPhtZyjPYddJ8yGPWreisp47H6iQjt3Lg8sZrzqMP5noy/go-ipfs-cmds/cli"
)
func
main
()
{
...
...
@@ -15,7 +15,7 @@ func main() {
if
err
!=
nil
{
panic
(
err
)
}
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
// create an emitter
...
...
@@ -29,7 +29,7 @@ func main() {
// call command in background
go
func
()
{
defer
close
(
wait
)
err
=
adder
.
RootCmd
.
Call
(
req
,
re
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -39,6 +39,6 @@ func main() {
// wait until command has returned and exit
ret
:=
<-
retCh
<-
wait
os
.
Exit
(
ret
)
}
examples/adder/remote/client/main.go
View file @
f3b5b7b4
...
...
@@ -26,7 +26,7 @@ func main() {
if
err
!=
nil
{
panic
(
err
)
}
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
// create an emitter
...
...
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