Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b1efb997
提交
b1efb997
authored
10月 26, 2018
作者:
Overbool
提交者:
Steven Allen
11月 06, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(cmds): use new cmds lib in config
License: MIT Signed-off-by:
Overbool
<
overbool.xu@gmail.com
>
上级
b2badfbb
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
77 行增加
和
143 行删除
+77
-143
active.go
core/commands/active.go
+1
-1
config.go
core/commands/config.go
+74
-140
root.go
core/commands/root.go
+1
-1
sysdiag.go
core/commands/sysdiag.go
+1
-1
没有找到文件。
core/commands/active.go
浏览文件 @
b1efb997
...
...
@@ -34,7 +34,7 @@ Lists running and recently run commands.
"clear"
:
clearInactiveCmd
,
"set-time"
:
setRequestClearCmd
,
},
Encoders
:
cmds
.
EncoderMap
{
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
[]
*
cmds
.
ReqLogEntry
)
error
{
verbose
,
_
:=
req
.
Options
[
verboseOptionName
]
.
(
bool
)
...
...
core/commands/config.go
浏览文件 @
b1efb997
package
commands
import
(
"bytes"
"encoding/json"
"errors"
"fmt"
...
...
@@ -11,11 +10,11 @@ import (
"os/exec"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
e
"github.com/ipfs/go-ipfs/core/commands/e"
oldcmds
"github.com/ipfs/go-ipfs/commands"
repo
"github.com/ipfs/go-ipfs/repo"
fsrepo
"github.com/ipfs/go-ipfs/repo/fsrepo"
cmds
"gx/ipfs/QmRRovo1DE6i5cMjCbf19mQCSuszF6SKwdZNUMS7MtBnH1/go-ipfs-cmds"
"gx/ipfs/QmP2i47tnU23ijdshrZtuvrSkQPtf9HhsMb9fwGVe8owj2/jsondiff"
config
"gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
...
...
@@ -60,7 +59,12 @@ Set the value of the 'Datastore.Path' key:
$ ipfs config Datastore.Path ~/.ipfs/datastore
`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"show"
:
configShowCmd
,
"edit"
:
configEditCmd
,
"replace"
:
configReplaceCmd
,
"profile"
:
configProfileCmd
,
},
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
StringArg
(
"key"
,
true
,
false
,
"The key of the config entry (e.g.
\"
Addresses.API
\"
)."
),
cmdkit
.
StringArg
(
"value"
,
false
,
false
,
"The value to set the config entry to."
),
...
...
@@ -69,46 +73,37 @@ Set the value of the 'Datastore.Path' key:
cmdkit
.
BoolOption
(
configBoolOptionName
,
"Set a boolean value."
),
cmdkit
.
BoolOption
(
configJSONOptionName
,
"Parse stringified JSON."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
args
:=
req
.
Arguments
()
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
args
:=
req
.
Arguments
key
:=
args
[
0
]
var
output
*
ConfigField
defer
func
()
{
if
output
!=
nil
{
res
.
SetOutput
(
output
)
}
else
{
res
.
SetOutput
(
nil
)
}
}()
// This is a temporary fix until we move the private key out of the config file
switch
strings
.
ToLower
(
key
)
{
case
"identity"
,
"identity.privkey"
:
res
.
SetError
(
fmt
.
Errorf
(
"cannot show or change private key through API"
),
cmdkit
.
ErrNormal
)
return
return
fmt
.
Errorf
(
"cannot show or change private key through API"
)
default
:
}
r
,
err
:=
fsrepo
.
Open
(
req
.
InvocContext
()
.
ConfigRoot
)
ctx
:=
env
.
(
*
oldcmds
.
Context
)
r
,
err
:=
fsrepo
.
Open
(
ctx
.
ConfigRoot
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
defer
r
.
Close
()
if
len
(
args
)
==
2
{
value
:=
args
[
1
]
if
parseJSON
,
_
,
_
:=
req
.
Option
(
configJSONOptionName
)
.
Bool
(
);
parseJSON
{
if
parseJSON
,
_
:=
req
.
Options
[
configJSONOptionName
]
.
(
bool
);
parseJSON
{
var
jsonVal
interface
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
value
),
&
jsonVal
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to unmarshal json. %s"
,
err
)
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
output
,
err
=
setConfig
(
r
,
key
,
jsonVal
)
}
else
if
isbool
,
_
,
_
:=
req
.
Option
(
configBoolOptionName
)
.
Bool
(
);
isbool
{
}
else
if
isbool
,
_
:=
req
.
Options
[
configBoolOptionName
]
.
(
bool
);
isbool
{
output
,
err
=
setConfig
(
r
,
key
,
value
==
"true"
)
}
else
{
output
,
err
=
setConfig
(
r
,
key
,
value
)
...
...
@@ -116,46 +111,28 @@ Set the value of the 'Datastore.Path' key:
}
else
{
output
,
err
=
getConfig
(
r
,
key
)
}
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
if
len
(
res
.
Request
()
.
Arguments
())
==
2
{
return
nil
,
nil
// dont output anything
}
if
res
.
Error
()
!=
nil
{
return
nil
,
res
.
Error
()
}
v
,
err
:=
unwrapOutput
(
res
.
Output
())
if
err
!=
nil
{
return
nil
,
err
}
vf
,
ok
:=
v
.
(
*
ConfigField
)
if
!
ok
{
return
nil
,
e
.
TypeErr
(
vf
,
v
)
return
res
.
Emit
(
output
)
},
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
ConfigField
)
error
{
if
len
(
req
.
Arguments
)
==
2
{
return
nil
}
buf
,
err
:=
config
.
HumanOutput
(
vf
.
Value
)
buf
,
err
:=
config
.
HumanOutput
(
out
.
Value
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
buf
=
append
(
buf
,
byte
(
'\n'
))
return
bytes
.
NewReader
(
buf
),
nil
},
fmt
.
Fprintln
(
w
,
string
(
buf
))
return
nil
}
)
,
},
Type
:
ConfigField
{},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"show"
:
configShowCmd
,
"edit"
:
configEditCmd
,
"replace"
:
configReplaceCmd
,
"profile"
:
configProfileCmd
,
},
}
var
configShowCmd
=
&
cmds
.
Command
{
...
...
@@ -166,57 +143,41 @@ NOTE: For security reasons, this command will omit your private key. If you woul
`
,
},
Type
:
map
[
string
]
interface
{}{},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
cfgPath
:=
req
.
InvocContext
()
.
ConfigRoot
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
ctx
:=
env
.
(
*
oldcmds
.
Context
)
cfgPath
:=
ctx
.
ConfigRoot
fname
,
err
:=
config
.
Filename
(
cfgPath
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
data
,
err
:=
ioutil
.
ReadFile
(
fname
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
var
cfg
map
[
string
]
interface
{}
err
=
json
.
Unmarshal
(
data
,
&
cfg
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
err
=
scrubValue
(
cfg
,
[]
string
{
config
.
IdentityTag
,
config
.
PrivKeyTag
})
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
res
.
SetOutput
(
&
cfg
)
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
if
res
.
Error
()
!=
nil
{
return
nil
,
res
.
Error
()
}
v
,
err
:=
unwrapOutput
(
res
.
Output
())
if
err
!=
nil
{
return
nil
,
err
}
cfg
,
ok
:=
v
.
(
*
map
[
string
]
interface
{})
if
!
ok
{
return
nil
,
e
.
TypeErr
(
cfg
,
v
)
}
buf
,
err
:=
config
.
HumanOutput
(
cfg
)
return
res
.
Emit
(
&
cfg
)
},
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
map
[
string
]
interface
{})
error
{
buf
,
err
:=
config
.
HumanOutput
(
out
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
buf
=
append
(
buf
,
byte
(
'\n'
))
return
bytes
.
NewReader
(
buf
),
nil
},
fmt
.
Fprintln
(
w
,
string
(
buf
))
return
nil
}
)
,
},
}
...
...
@@ -270,17 +231,14 @@ variable set to your preferred text editor.
`
,
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
filename
,
err
:=
config
.
Filename
(
req
.
InvocContext
()
.
ConfigRoot
)
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
ctx
:=
env
.
(
*
oldcmds
.
Context
)
filename
,
err
:=
config
.
Filename
(
ctx
.
ConfigRoot
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
err
=
editConfig
(
filename
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
}
return
editConfig
(
filename
)
},
}
...
...
@@ -296,29 +254,21 @@ can't be undone.
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
FileArg
(
"file"
,
true
,
false
,
"The file to use as the new config."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
// has to be called
res
.
SetOutput
(
nil
)
r
,
err
:=
fsrepo
.
Open
(
req
.
InvocContext
()
.
ConfigRoot
)
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
ctx
:=
env
.
(
*
oldcmds
.
Context
)
r
,
err
:=
fsrepo
.
Open
(
ctx
.
ConfigRoot
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
defer
r
.
Close
()
file
,
err
:=
req
.
Files
()
.
NextFile
()
file
,
err
:=
req
.
Files
.
NextFile
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
defer
file
.
Close
()
err
=
replaceConfig
(
r
,
file
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
}
return
replaceConfig
(
r
,
file
)
},
}
...
...
@@ -346,58 +296,42 @@ var configProfileApplyCmd = &cmds.Command{
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
StringArg
(
"profile"
,
true
,
false
,
"The profile to apply to the config."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
profile
,
ok
:=
config
.
Profiles
[
req
.
Arguments
()
[
0
]]
Run
:
func
(
req
*
cmds
.
Request
,
res
cmds
.
ResponseEmitter
,
env
cmds
.
Environment
)
error
{
profile
,
ok
:=
config
.
Profiles
[
req
.
Arguments
[
0
]]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"%s is not a profile"
,
req
.
Arguments
()[
0
]),
cmdkit
.
ErrNormal
)
return
return
fmt
.
Errorf
(
"%s is not a profile"
,
req
.
Arguments
[
0
])
}
dryRun
,
_
,
_
:=
req
.
Option
(
"dry-run"
)
.
Bool
()
oldCfg
,
newCfg
,
err
:=
transformConfig
(
req
.
InvocContext
()
.
ConfigRoot
,
req
.
Arguments
()[
0
],
profile
.
Transform
,
dryRun
)
dryRun
,
_
:=
req
.
Options
[
"dry-run"
]
.
(
bool
)
ctx
:=
env
.
(
*
oldcmds
.
Context
)
oldCfg
,
newCfg
,
err
:=
transformConfig
(
ctx
.
ConfigRoot
,
req
.
Arguments
[
0
],
profile
.
Transform
,
dryRun
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
oldCfgMap
,
err
:=
scrubPrivKey
(
oldCfg
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
newCfgMap
,
err
:=
scrubPrivKey
(
newCfg
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmdkit
.
ErrNormal
)
return
return
err
}
re
s
.
SetOutpu
t
(
&
ConfigUpdateOutput
{
re
turn
res
.
Emi
t
(
&
ConfigUpdateOutput
{
OldCfg
:
oldCfgMap
,
NewCfg
:
newCfgMap
,
})
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
if
res
.
Error
()
!=
nil
{
return
nil
,
res
.
Error
()
}
v
,
err
:=
unwrapOutput
(
res
.
Output
())
if
err
!=
nil
{
return
nil
,
err
}
apply
,
ok
:=
v
.
(
*
ConfigUpdateOutput
)
if
!
ok
{
return
nil
,
e
.
TypeErr
(
apply
,
v
)
}
diff
:=
jsondiff
.
Compare
(
apply
.
OldCfg
,
apply
.
NewCfg
)
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
ConfigUpdateOutput
)
error
{
diff
:=
jsondiff
.
Compare
(
out
.
OldCfg
,
out
.
NewCfg
)
buf
:=
jsondiff
.
Format
(
diff
)
return
strings
.
NewReader
(
string
(
buf
)),
nil
},
fmt
.
Fprint
(
w
,
string
(
buf
))
return
nil
}),
},
Type
:
ConfigUpdateOutput
{},
}
...
...
core/commands/root.go
浏览文件 @
b1efb997
...
...
@@ -123,7 +123,7 @@ var rootSubcommands = map[string]*cmds.Command{
"repo"
:
RepoCmd
,
"stats"
:
StatsCmd
,
"bootstrap"
:
lgc
.
NewCommand
(
BootstrapCmd
),
"config"
:
lgc
.
NewCommand
(
ConfigCmd
)
,
"config"
:
ConfigCmd
,
"dag"
:
dag
.
DagCmd
,
"dht"
:
DhtCmd
,
"diag"
:
DiagCmd
,
...
...
core/commands/sysdiag.go
浏览文件 @
b1efb997
...
...
@@ -5,8 +5,8 @@ import (
"path"
"runtime"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
version
"github.com/ipfs/go-ipfs"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
cmds
"gx/ipfs/QmRRovo1DE6i5cMjCbf19mQCSuszF6SKwdZNUMS7MtBnH1/go-ipfs-cmds"
manet
"gx/ipfs/QmQVUtnrNGtCRkCMpXgpApfzQjc8FDaDVxHqWH8cnZQeh5/go-multiaddr-net"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论