Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
96a07267
提交
96a07267
authored
12月 06, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
address CR feedback
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
b99b7782
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
79 行增加
和
68 行删除
+79
-68
command.go
commands/command.go
+0
-67
external.go
core/commands/external.go
+78
-0
root.go
core/commands/root.go
+1
-1
没有找到文件。
commands/command.go
浏览文件 @
96a07267
...
@@ -9,12 +9,9 @@ output to the user, including text, JSON, and XML marshallers.
...
@@ -9,12 +9,9 @@ output to the user, including text, JSON, and XML marshallers.
package
commands
package
commands
import
(
import
(
"bytes"
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"os"
"os/exec"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -269,67 +266,3 @@ func checkArgValue(v string, found bool, def Argument) error {
...
@@ -269,67 +266,3 @@ func checkArgValue(v string, found bool, def Argument) error {
func
ClientError
(
msg
string
)
error
{
func
ClientError
(
msg
string
)
error
{
return
&
Error
{
Code
:
ErrClient
,
Message
:
msg
}
return
&
Error
{
Code
:
ErrClient
,
Message
:
msg
}
}
}
func
ExternalBinary
()
*
Command
{
return
&
Command
{
Arguments
:
[]
Argument
{
StringArg
(
"args"
,
false
,
true
,
"arguments for subcommand"
),
},
External
:
true
,
Run
:
func
(
req
Request
,
res
Response
)
{
binname
:=
strings
.
Join
(
append
([]
string
{
"ipfs"
},
req
.
Path
()
...
),
"-"
)
_
,
err
:=
exec
.
LookPath
(
binname
)
if
err
!=
nil
{
// special case for '--help' on uninstalled binaries.
if
req
.
Arguments
()[
0
]
==
"--help"
{
buf
:=
new
(
bytes
.
Buffer
)
fmt
.
Fprintf
(
buf
,
"%s is an 'external' command.
\n
"
,
binname
)
fmt
.
Fprintf
(
buf
,
"it does not currently appear to be installed.
\n
"
)
fmt
.
Fprintf
(
buf
,
"please refer to the ipfs documentation for instructions
\n
"
)
res
.
SetOutput
(
buf
)
return
}
res
.
SetError
(
fmt
.
Errorf
(
"%s not installed."
),
ErrNormal
)
return
}
r
,
w
:=
io
.
Pipe
()
cmd
:=
exec
.
Command
(
binname
,
req
.
Arguments
()
...
)
// TODO: make commands lib be able to pass stdin through daemon
//cmd.Stdin = req.Stdin()
cmd
.
Stdin
=
io
.
LimitReader
(
nil
,
0
)
cmd
.
Stdout
=
w
cmd
.
Stderr
=
w
// setup env of child program
env
:=
os
.
Environ
()
nd
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
==
nil
{
env
=
append
(
env
,
fmt
.
Sprintf
(
"IPFS_ONLINE=%t"
,
nd
.
OnlineMode
()))
}
cmd
.
Env
=
env
err
=
cmd
.
Start
()
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"failed to start subcommand: %s"
,
err
),
ErrNormal
)
return
}
res
.
SetOutput
(
r
)
go
func
()
{
err
=
cmd
.
Wait
()
if
err
!=
nil
{
res
.
SetError
(
err
,
ErrNormal
)
}
w
.
Close
()
}()
},
}
}
core/commands/external.go
0 → 100644
浏览文件 @
96a07267
package
commands
import
(
"bytes"
"fmt"
"io"
"os"
"os/exec"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
)
func
ExternalBinary
()
*
cmds
.
Command
{
return
&
cmds
.
Command
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"args"
,
false
,
true
,
"arguments for subcommand"
),
},
External
:
true
,
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
binname
:=
strings
.
Join
(
append
([]
string
{
"ipfs"
},
req
.
Path
()
...
),
"-"
)
_
,
err
:=
exec
.
LookPath
(
binname
)
if
err
!=
nil
{
// special case for '--help' on uninstalled binaries.
for
_
,
arg
:=
range
req
.
Arguments
()
{
if
arg
==
"--help"
||
arg
==
"-h"
{
buf
:=
new
(
bytes
.
Buffer
)
fmt
.
Fprintf
(
buf
,
"%s is an 'external' command.
\n
"
,
binname
)
fmt
.
Fprintf
(
buf
,
"it does not currently appear to be installed.
\n
"
)
fmt
.
Fprintf
(
buf
,
"please refer to the ipfs documentation for instructions
\n
"
)
res
.
SetOutput
(
buf
)
return
}
}
res
.
SetError
(
fmt
.
Errorf
(
"%s not installed."
),
cmds
.
ErrNormal
)
return
}
r
,
w
:=
io
.
Pipe
()
cmd
:=
exec
.
Command
(
binname
,
req
.
Arguments
()
...
)
// TODO: make commands lib be able to pass stdin through daemon
//cmd.Stdin = req.Stdin()
cmd
.
Stdin
=
io
.
LimitReader
(
nil
,
0
)
cmd
.
Stdout
=
w
cmd
.
Stderr
=
w
// setup env of child program
env
:=
os
.
Environ
()
nd
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
==
nil
{
env
=
append
(
env
,
fmt
.
Sprintf
(
"IPFS_ONLINE=%t"
,
nd
.
OnlineMode
()))
}
cmd
.
Env
=
env
err
=
cmd
.
Start
()
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"failed to start subcommand: %s"
,
err
),
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
r
)
go
func
()
{
err
=
cmd
.
Wait
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
}
w
.
Close
()
}()
},
}
}
core/commands/root.go
浏览文件 @
96a07267
...
@@ -111,7 +111,7 @@ var rootSubcommands = map[string]*cmds.Command{
...
@@ -111,7 +111,7 @@ var rootSubcommands = map[string]*cmds.Command{
"tar"
:
TarCmd
,
"tar"
:
TarCmd
,
"tour"
:
tourCmd
,
"tour"
:
tourCmd
,
"file"
:
unixfs
.
UnixFSCmd
,
"file"
:
unixfs
.
UnixFSCmd
,
"update"
:
cmds
.
ExternalBinary
(),
"update"
:
ExternalBinary
(),
"version"
:
VersionCmd
,
"version"
:
VersionCmd
,
"bitswap"
:
BitswapCmd
,
"bitswap"
:
BitswapCmd
,
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论