Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
085217eb
Unverified
提交
085217eb
authored
11月 09, 2018
作者:
Steven Allen
提交者:
GitHub
11月 09, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5730 from overbool/refactor/cmds/update
cmds/update: use new cmds lib
上级
19a66204
5002d59d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
28 行删除
+27
-28
external.go
core/commands/external.go
+26
-27
root.go
core/commands/root.go
+1
-1
没有找到文件。
core/commands/external.go
浏览文件 @
085217eb
...
@@ -8,9 +8,10 @@ import (
...
@@ -8,9 +8,10 @@ import (
"os/exec"
"os/exec"
"strings"
"strings"
c
m
ds
"github.com/ipfs/go-ipfs/commands"
c
omman
ds
"github.com/ipfs/go-ipfs/commands"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
cmds
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
cmdkit
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
)
)
func
ExternalBinary
()
*
cmds
.
Command
{
func
ExternalBinary
()
*
cmds
.
Command
{
...
@@ -19,29 +20,27 @@ func ExternalBinary() *cmds.Command {
...
@@ -19,29 +20,27 @@ func ExternalBinary() *cmds.Command {
cmdkit
.
StringArg
(
"args"
,
false
,
true
,
"Arguments for subcommand."
),
cmdkit
.
StringArg
(
"args"
,
false
,
true
,
"Arguments for subcommand."
),
},
},
External
:
true
,
External
:
true
,
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
binname
:=
strings
.
Join
(
append
([]
string
{
"ipfs"
},
req
.
Path
()
...
),
"-"
)
binname
:=
strings
.
Join
(
append
([]
string
{
"ipfs"
},
req
.
Path
...
),
"-"
)
_
,
err
:=
exec
.
LookPath
(
binname
)
_
,
err
:=
exec
.
LookPath
(
binname
)
if
err
!=
nil
{
if
err
!=
nil
{
// special case for '--help' on uninstalled binaries.
// special case for '--help' on uninstalled binaries.
for
_
,
arg
:=
range
req
.
Arguments
()
{
for
_
,
arg
:=
range
req
.
Arguments
{
if
arg
==
"--help"
||
arg
==
"-h"
{
if
arg
==
"--help"
||
arg
==
"-h"
{
buf
:=
new
(
bytes
.
Buffer
)
buf
:=
new
(
bytes
.
Buffer
)
fmt
.
Fprintf
(
buf
,
"%s is an 'external' command.
\n
"
,
binname
)
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
,
"It does not currently appear to be installed.
\n
"
)
fmt
.
Fprintf
(
buf
,
"Please refer to the ipfs documentation for instructions.
\n
"
)
fmt
.
Fprintf
(
buf
,
"Please refer to the ipfs documentation for instructions.
\n
"
)
res
.
SetOutput
(
buf
)
return
res
.
Emit
(
buf
)
return
}
}
}
}
res
.
SetError
(
fmt
.
Errorf
(
"%s not installed"
,
binname
),
cmdkit
.
ErrNormal
)
return
fmt
.
Errorf
(
"%s not installed"
,
binname
)
return
}
}
r
,
w
:=
io
.
Pipe
()
r
,
w
:=
io
.
Pipe
()
cmd
:=
exec
.
Command
(
binname
,
req
.
Arguments
()
...
)
cmd
:=
exec
.
Command
(
binname
,
req
.
Arguments
...
)
// TODO: make commands lib be able to pass stdin through daemon
// TODO: make commands lib be able to pass stdin through daemon
//cmd.Stdin = req.Stdin()
//cmd.Stdin = req.Stdin()
...
@@ -50,39 +49,39 @@ func ExternalBinary() *cmds.Command {
...
@@ -50,39 +49,39 @@ func ExternalBinary() *cmds.Command {
cmd
.
Stderr
=
w
cmd
.
Stderr
=
w
// setup env of child program
// setup env of child program
env
:=
os
.
Environ
()
os
env
:=
os
.
Environ
()
// Get the node iff already defined.
// Get the node iff already defined.
if
req
.
InvocContext
()
.
Online
{
if
cctx
,
ok
:=
env
.
(
*
commands
.
Context
);
ok
&&
cctx
.
Online
{
nd
,
err
:=
req
.
InvocContext
()
.
GetNode
()
nd
,
err
:=
cctx
.
GetNode
()
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
return
fmt
.
Errorf
(
"failed to start ipfs node: %s"
,
err
)
"failed to start ipfs node: %s"
,
err
,
),
cmdkit
.
ErrFatal
)
return
}
}
env
=
append
(
env
,
fmt
.
Sprintf
(
"IPFS_ONLINE=%t"
,
nd
.
OnlineMode
()))
osenv
=
append
(
os
env
,
fmt
.
Sprintf
(
"IPFS_ONLINE=%t"
,
nd
.
OnlineMode
()))
}
}
cmd
.
Env
=
env
cmd
.
Env
=
os
env
err
=
cmd
.
Start
()
err
=
cmd
.
Start
()
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
fmt
.
Errorf
(
"failed to start subcommand: %s"
,
err
),
cmdkit
.
ErrNormal
)
return
fmt
.
Errorf
(
"failed to start subcommand: %s"
,
err
)
return
}
}
res
.
SetOutput
(
r
)
errC
:=
make
(
chan
erro
r
)
go
func
()
{
go
func
()
{
var
err
error
defer
func
()
{
errC
<-
err
}()
err
=
cmd
.
Wait
()
err
=
cmd
.
Wait
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
}
w
.
Close
()
w
.
Close
()
}()
}()
err
=
res
.
Emit
(
r
)
if
err
!=
nil
{
return
err
}
return
<-
errC
},
},
}
}
}
}
core/commands/root.go
浏览文件 @
085217eb
...
@@ -139,7 +139,7 @@ var rootSubcommands = map[string]*cmds.Command{
...
@@ -139,7 +139,7 @@ var rootSubcommands = map[string]*cmds.Command{
"swarm"
:
SwarmCmd
,
"swarm"
:
SwarmCmd
,
"tar"
:
TarCmd
,
"tar"
:
TarCmd
,
"file"
:
unixfs
.
UnixFSCmd
,
"file"
:
unixfs
.
UnixFSCmd
,
"update"
:
lgc
.
NewCommand
(
ExternalBinary
()
),
"update"
:
ExternalBinary
(
),
"urlstore"
:
urlStoreCmd
,
"urlstore"
:
urlStoreCmd
,
"version"
:
VersionCmd
,
"version"
:
VersionCmd
,
"shutdown"
:
daemonShutdownCmd
,
"shutdown"
:
daemonShutdownCmd
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论