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-unixfs
Commits
520240d3
Commit
520240d3
authored
Nov 07, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(commands2/tour) impl
parent
c65b01c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
2 deletions
+154
-2
cmd/ipfs2/ipfs.go
cmd/ipfs2/ipfs.go
+3
-2
cmd/ipfs2/tour.go
cmd/ipfs2/tour.go
+151
-0
No files found.
cmd/ipfs2/ipfs.go
View file @
520240d3
...
@@ -9,7 +9,8 @@ var Root = &cmds.Command{
...
@@ -9,7 +9,8 @@ var Root = &cmds.Command{
Options
:
commands
.
Root
.
Options
,
Options
:
commands
.
Root
.
Options
,
Help
:
commands
.
Root
.
Help
,
Help
:
commands
.
Root
.
Help
,
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"daemon"
:
daemonCmd
,
"daemon"
:
daemonCmd
,
// TODO name
"init"
:
initCmd
,
"init"
:
initCmd
,
// TODO name
"tour"
:
cmdTour
,
},
},
}
}
cmd/ipfs2/tour.go
0 → 100644
View file @
520240d3
package
main
import
(
"bytes"
"fmt"
"io"
"os"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core/commands2/internal"
"github.com/jbenet/go-ipfs/tour"
)
var
cmdTour
=
&
cmds
.
Command
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
Argument
{
"number"
,
cmds
.
ArgString
,
false
,
true
},
},
// TODO UsageLine: "tour [<number>]",
// TODO Short: "Take the IPFS Tour.",
Help
:
`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
`
,
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"list"
:
cmdIpfsTourList
,
"next"
:
cmdIpfsTourNext
,
"restart"
:
cmdIpfsTourRestart
,
},
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
out
:=
new
(
bytes
.
Buffer
)
cfg
:=
req
.
Context
()
.
Config
strs
,
err
:=
internal
.
ToStrings
(
req
.
Arguments
())
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
topic
:=
tour
.
TopicID
(
cfg
.
Tour
.
Last
)
if
len
(
strs
)
>
0
{
topic
=
tour
.
TopicID
(
strs
[
0
])
}
err
=
tourShow
(
out
,
topic
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
out
)
},
}
var
cmdIpfsTourNext
=
&
cmds
.
Command
{
Help
:
"Show the next IPFS Tour topic."
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
var
w
bytes
.
Buffer
cfg
:=
req
.
Context
()
.
Config
path
:=
req
.
Context
()
.
ConfigRoot
topic
:=
tour
.
NextTopic
(
tour
.
TopicID
(
cfg
.
Tour
.
Last
))
if
err
:=
tourShow
(
&
w
,
topic
);
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
// topic changed, not last. write it out.
if
string
(
topic
)
!=
cfg
.
Tour
.
Last
{
cfg
.
Tour
.
Last
=
string
(
topic
)
err
:=
writeConfig
(
path
,
cfg
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
}
w
.
WriteTo
(
os
.
Stdout
)
// TODO write to res.SetValue
},
}
var
cmdIpfsTourRestart
=
&
cmds
.
Command
{
Help
:
"Restart the IPFS Tour."
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
path
:=
req
.
Context
()
.
ConfigRoot
cfg
:=
req
.
Context
()
.
Config
cfg
.
Tour
.
Last
=
""
err
:=
writeConfig
(
path
,
cfg
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
}
},
}
var
cmdIpfsTourList
=
&
cmds
.
Command
{
Help
:
"Show a list of IPFS Tour topics."
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
var
w
bytes
.
Buffer
tourListCmd
(
&
w
,
req
.
Context
()
.
Config
)
w
.
WriteTo
(
os
.
Stdout
)
// TODO use res.SetOutput(output)
},
}
func
tourListCmd
(
w
io
.
Writer
,
cfg
*
config
.
Config
)
{
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
.
Fprintf
(
w
,
"- %c %-5.5s %s
\n
"
,
c
,
id
,
t
.
Title
)
}
}
func
tourShow
(
w
io
.
Writer
,
id
tour
.
ID
)
error
{
t
,
found
:=
tour
.
Topics
[
id
]
if
!
found
{
return
fmt
.
Errorf
(
"no topic with id: %s"
,
id
)
}
fmt
.
Fprintf
(
w
,
"Tour %s - %s
\n\n
%s
\n
"
,
t
.
ID
,
t
.
Title
,
t
.
Text
)
return
nil
}
// TODO share func
func
writeConfig
(
path
string
,
cfg
*
config
.
Config
)
error
{
filename
,
err
:=
config
.
Filename
(
path
)
if
err
!=
nil
{
return
err
}
return
config
.
WriteConfigFile
(
filename
,
cfg
)
}
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