root.go 3.26 KB
Newer Older
1 2 3
package commands

import (
4 5 6
	"io"
	"strings"

7
	cmds "github.com/ipfs/go-ipfs/commands"
8
	unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
9
	evlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
10 11
)

Jeromy's avatar
Jeromy committed
12
var log = evlog.Logger("core/commands")
Matt Bell's avatar
Matt Bell committed
13

14 15 16 17 18 19
type TestOutput struct {
	Foo string
	Bar int
}

var Root = &cmds.Command{
20
	Helptext: cmds.HelpText{
21 22 23 24
		Tagline: "global p2p merkle-dag filesystem",
		Synopsis: `
ipfs [<flags>] <command> [<arg>] ...
`,
25
		ShortDescription: `
26
BASIC COMMANDS
27

Markus Amalthea Magnuson's avatar
Markus Amalthea Magnuson committed
28
    init          Initialize ipfs local configuration
29 30
    add <path>    Add an object to ipfs
    cat <ref>     Show ipfs object data
31
    get <ref>     Download ipfs objects
32
    ls <ref>      List links from an object
33
    refs <ref>    List hashes of links from an object
34

35
DATA STRUCTURE COMMANDS
36

37 38
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
39
    file          Interact with Unix filesystem objects
40

41
ADVANCED COMMANDS
42

43
    daemon        Start a long-running daemon process
44
    mount         Mount an ipfs read-only mountpoint
45
    resolve       Resolve any type of name
46
    name          Publish or resolve IPNS names
47
    dns           Resolve DNS links
48
    pin           Pin objects to local storage
49
    repo gc       Garbage collect unpinned objects
50

51
NETWORK COMMANDS
52

53
    id            Show info about ipfs peers
54
    bootstrap     Add or remove bootstrap peers
55 56
    swarm         Manage connections to the p2p network
    dht           Query the dht for values or peers
57
    ping          Measure the latency of a connection
58
    diag          Print diagnostics
59

60
TOOL COMMANDS
61

62 63 64 65
    config        Manage configuration
    version       Show ipfs version information
    update        Download and apply go-ipfs updates
    commands      List all available commands
66 67

Use 'ipfs <command> --help' to learn more about each command.
68
`,
69
	},
70
	Options: []cmds.Option{
71 72
		cmds.StringOption("config", "c", "Path to the configuration file to use"),
		cmds.BoolOption("debug", "D", "Operate in debug mode"),
73 74
		cmds.BoolOption("help", "Show the full command help text"),
		cmds.BoolOption("h", "Show a short version of the command help text"),
75
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
76
	},
77 78
}

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
79 80 81
// commandsDaemonCmd is the "ipfs commands" command for daemon
var CommandsDaemonCmd = CommandsCmd(Root)

82
var rootSubcommands = map[string]*cmds.Command{
83 84 85 86
	"add":       AddCmd,
	"block":     BlockCmd,
	"bootstrap": BootstrapCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
87
	"commands":  CommandsDaemonCmd,
88
	"config":    ConfigCmd,
89
	"dht":       DhtCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
90
	"diag":      DiagCmd,
91
	"dns":       DNSCmd,
Matt Bell's avatar
Matt Bell committed
92
	"get":       GetCmd,
93 94 95 96 97 98 99
	"id":        IDCmd,
	"log":       LogCmd,
	"ls":        LsCmd,
	"mount":     MountCmd,
	"name":      NameCmd,
	"object":    ObjectCmd,
	"pin":       PinCmd,
100
	"ping":      PingCmd,
101
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
102
	"repo":      RepoCmd,
103
	"resolve":   ResolveCmd,
Jeromy's avatar
Jeromy committed
104
	"stats":     StatsCmd,
105
	"swarm":     SwarmCmd,
rht's avatar
rht committed
106
	"tour":      tourCmd,
107
	"file":      unixfs.UnixFSCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
108
	"update":    UpdateCmd,
109
	"version":   VersionCmd,
110
	"bitswap":   BitswapCmd,
111
}
112 113

func init() {
114
	Root.Subcommands = rootSubcommands
115
}
116 117 118 119 120

type MessageOutput struct {
	Message string
}

121 122
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
123
}