Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6f7bab38
提交
6f7bab38
authored
10月 26, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tour: command
上级
54c2a14c
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
273 行增加
和
18 行删除
+273
-18
bootstrap.go
cmd/ipfs/bootstrap.go
+0
-15
config.go
cmd/ipfs/config.go
+19
-3
ipfs.go
cmd/ipfs/ipfs.go
+1
-0
tour.go
cmd/ipfs/tour.go
+134
-0
config.go
config/config.go
+7
-0
all.go
tour/all.go
+26
-0
tour.go
tour/tour.go
+86
-0
没有找到文件。
cmd/ipfs/bootstrap.go
浏览文件 @
6f7bab38
...
...
@@ -187,21 +187,6 @@ func bootstrapListCmd(c *commander.Command, inp []string) error {
return
nil
}
func
writeConfig
(
c
*
commander
.
Command
,
cfg
*
config
.
Config
)
error
{
confdir
,
err
:=
getConfigDir
(
c
)
if
err
!=
nil
{
return
err
}
filename
,
err
:=
config
.
Filename
(
confdir
)
if
err
!=
nil
{
return
err
}
return
config
.
WriteConfigFile
(
filename
,
cfg
)
}
func
bootstrapInputToPeers
(
input
[]
string
)
([]
*
config
.
BootstrapPeer
,
error
)
{
split
:=
func
(
addr
string
)
(
string
,
string
)
{
idx
:=
strings
.
LastIndex
(
addr
,
"/"
)
...
...
cmd/ipfs/config.go
浏览文件 @
6f7bab38
...
...
@@ -3,13 +3,14 @@ package main
import
(
"errors"
"fmt"
"io"
"os"
"os/exec"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
"io"
"os"
"os/exec"
)
var
cmdIpfsConfig
=
&
commander
.
Command
{
...
...
@@ -125,3 +126,18 @@ func configEditor(filename string) error {
cmd
.
Stdin
,
cmd
.
Stdout
,
cmd
.
Stderr
=
os
.
Stdin
,
os
.
Stdout
,
os
.
Stderr
return
cmd
.
Run
()
}
func
writeConfig
(
c
*
commander
.
Command
,
cfg
*
config
.
Config
)
error
{
confdir
,
err
:=
getConfigDir
(
c
)
if
err
!=
nil
{
return
err
}
filename
,
err
:=
config
.
Filename
(
confdir
)
if
err
!=
nil
{
return
err
}
return
config
.
WriteConfigFile
(
filename
,
cfg
)
}
cmd/ipfs/ipfs.go
浏览文件 @
6f7bab38
...
...
@@ -73,6 +73,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsUpdate
,
cmdIpfsLog
,
cmdIpfsPin
,
cmdIpfsTour
,
},
Flag
:
*
flag
.
NewFlagSet
(
"ipfs"
,
flag
.
ExitOnError
),
}
...
...
cmd/ipfs/tour.go
0 → 100644
浏览文件 @
6f7bab38
// +build linux darwin freebsd
package
main
import
(
"fmt"
config
"github.com/jbenet/go-ipfs/config"
tour
"github.com/jbenet/go-ipfs/tour"
commander
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
)
var
cmdIpfsTour
=
&
commander
.
Command
{
UsageLine
:
"tour [<number>]"
,
Short
:
"Take the IPFS Tour."
,
Long
:
`ipfs tour - Take the IPFS Tour.
ipfs tour [<number>] - Show tour topic. Default to current.
ipfs tour next - Show the next tour topic.
ipfs tour list - Show a list of topics.
ipfs tour restart - Restart the tour.
This is a tour that takes you through various IPFS concepts,
features, and tools to make sure you get up to speed with
IPFS very quickly. To start, run:
ipfs tour
`
,
Run
:
tourCmd
,
Subcommands
:
[]
*
commander
.
Command
{
cmdIpfsTourNext
,
cmdIpfsTourList
,
cmdIpfsTourRestart
,
},
}
var
cmdIpfsTourNext
=
&
commander
.
Command
{
UsageLine
:
"next"
,
Short
:
"Show the next IPFS Tour topic."
,
Run
:
tourNextCmd
,
}
var
cmdIpfsTourList
=
&
commander
.
Command
{
UsageLine
:
"list"
,
Short
:
"Show a list of IPFS Tour topics."
,
Run
:
tourListCmd
,
}
var
cmdIpfsTourRestart
=
&
commander
.
Command
{
UsageLine
:
"restart"
,
Short
:
"Restart the IPFS Tour."
,
Run
:
tourRestartCmd
,
}
func
tourCmd
(
c
*
commander
.
Command
,
inp
[]
string
)
error
{
cfg
,
err
:=
getConfig
(
c
)
if
err
!=
nil
{
return
err
}
topic
:=
tour
.
TopicID
(
cfg
.
Tour
.
Last
)
if
len
(
inp
)
>
0
{
topic
=
tour
.
TopicID
(
inp
[
0
])
}
return
tourShow
(
topic
)
}
func
tourNextCmd
(
c
*
commander
.
Command
,
_
[]
string
)
error
{
cfg
,
err
:=
getConfig
(
c
)
if
err
!=
nil
{
return
err
}
topic
:=
tour
.
NextTopic
(
tour
.
TopicID
(
cfg
.
Tour
.
Last
))
if
err
:=
tourShow
(
topic
);
err
!=
nil
{
return
err
}
// if topic didn't change (last) done
if
string
(
topic
)
==
cfg
.
Tour
.
Last
{
return
nil
}
// topic changed, not last. write it out.
cfg
.
Tour
.
Last
=
string
(
topic
)
return
writeConfig
(
c
,
cfg
)
}
func
tourListCmd
(
c
*
commander
.
Command
,
_
[]
string
)
error
{
cfg
,
err
:=
getConfig
(
c
)
if
err
!=
nil
{
return
err
}
lastid
:=
tour
.
TopicID
(
cfg
.
Tour
.
Last
)
for
_
,
id
:=
range
tour
.
IDs
{
c
:=
' '
switch
{
case
id
==
lastid
:
c
=
'*'
case
id
.
LessThan
(
lastid
)
:
c
=
'✓'
}
t
:=
tour
.
Topics
[
id
]
fmt
.
Printf
(
"- %c %5.5s %s
\n
"
,
c
,
id
,
t
.
Title
)
}
return
nil
}
func
tourRestartCmd
(
c
*
commander
.
Command
,
_
[]
string
)
error
{
cfg
,
err
:=
getConfig
(
c
)
if
err
!=
nil
{
return
err
}
cfg
.
Tour
.
Last
=
""
return
writeConfig
(
c
,
cfg
)
}
func
tourShow
(
id
tour
.
ID
)
error
{
t
,
found
:=
tour
.
Topics
[
id
]
if
!
found
{
return
fmt
.
Errorf
(
"no topic with id: %s"
,
id
)
}
fmt
.
Printf
(
"Tour %s - %s
\n\n
%s
\n
"
,
t
.
ID
,
t
.
Title
,
t
.
Text
)
return
nil
}
func
lastTour
(
cfg
*
config
.
Config
)
string
{
return
""
}
config/config.go
浏览文件 @
6f7bab38
...
...
@@ -47,6 +47,12 @@ func (bp *BootstrapPeer) String() string {
return
bp
.
Address
+
"/"
+
bp
.
PeerID
}
// Tour stores the ipfs tour read-list and resume point
type
Tour
struct
{
Last
string
// last tour topic read
// Done []string // all topics done so far
}
// Config is used to load IPFS config files.
type
Config
struct
{
Identity
Identity
// local node's peer identity
...
...
@@ -55,6 +61,7 @@ type Config struct {
Mounts
Mounts
// local node's mount points
Version
Version
// local node's version management
Bootstrap
[]
*
BootstrapPeer
// local nodes's bootstrap peers
Tour
Tour
// local node's tour position
}
// DefaultPathRoot is the path to the default config dir location.
...
...
tour/all.go
0 → 100644
浏览文件 @
6f7bab38
package
tour
import
"sort"
func
init
()
{
for
_
,
t
:=
range
allTopics
{
Topics
[
t
.
ID
]
=
t
IDs
=
append
(
IDs
,
t
.
ID
)
}
sort
.
Sort
(
IDSlice
(
IDs
))
}
// Topics contains a mapping of Tour Topic ID to Topic
var
allTopics
=
[]
Topic
{
Topic
{
ID
:
ID
(
"0"
),
Title
:
"Hello Mars"
,
Text
:
"Hello Mars"
,
},
Topic
{
ID
:
ID
(
"0.1"
),
Title
:
"Hello Mars 2"
,
Text
:
"Hello Mars 2"
,
},
}
tour/tour.go
0 → 100644
浏览文件 @
6f7bab38
package
tour
import
(
"strconv"
"strings"
u
"github.com/jbenet/go-ipfs/util"
)
var
log
=
u
.
Logger
(
"tour"
)
// ID is a string identifier for topics
type
ID
string
// LessThan returns whether this ID is sorted earlier than another.
func
(
i
ID
)
LessThan
(
o
ID
)
bool
{
return
compareDottedInts
(
string
(
i
),
string
(
o
))
}
// IDSlice implements the sort interface for ID slices.
type
IDSlice
[]
ID
func
(
a
IDSlice
)
Len
()
int
{
return
len
(
a
)
}
func
(
a
IDSlice
)
Swap
(
i
,
j
int
)
{
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
}
func
(
a
IDSlice
)
Less
(
i
,
j
int
)
bool
{
return
a
[
i
]
.
LessThan
(
a
[
j
])
}
// Topic is a type of objects that structures a tour topic.
type
Topic
struct
{
ID
ID
Title
string
Text
string
}
// Topics is a sorted list of topic IDs
var
IDs
[]
ID
// Topics contains a mapping of Tour Topic ID to Topic
var
Topics
=
map
[
ID
]
Topic
{}
// NextTopic returns the next in-order topic
func
NextTopic
(
topic
ID
)
ID
{
for
_
,
id
:=
range
IDs
{
if
topic
.
LessThan
(
id
)
{
return
id
}
}
return
topic
// last one, it seems.
}
// TopicID returns a valid tour topic ID from given string
func
TopicID
(
t
string
)
ID
{
if
t
==
""
{
// if empty, use first ID
return
IDs
[
0
]
}
return
ID
(
t
)
}
func
compareDottedInts
(
i
,
o
string
)
bool
{
is
:=
strings
.
Split
(
i
,
"."
)
os
:=
strings
.
Split
(
o
,
"."
)
for
n
,
vis
:=
range
is
{
if
n
>=
len
(
os
)
{
return
false
// os is smaller.
}
vos
:=
os
[
n
]
ivis
,
err1
:=
strconv
.
Atoi
(
vis
)
ivos
,
err2
:=
strconv
.
Atoi
(
vos
)
if
err1
!=
nil
||
err2
!=
nil
{
log
.
Error
(
err1
)
log
.
Error
(
err2
)
panic
(
"tour ID LessThan: not an int"
)
}
if
ivis
<
ivos
{
return
true
}
if
ivis
>
ivos
{
return
false
}
}
return
len
(
os
)
>
len
(
is
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论