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

import (
4 5 6
	"io"
	"strings"

7
	cmds "github.com/ipfs/go-ipfs/commands"
Jeromy's avatar
Jeromy committed
8
	files "github.com/ipfs/go-ipfs/core/commands/files"
9
	ocmd "github.com/ipfs/go-ipfs/core/commands/object"
10
	unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
Jeromy's avatar
Jeromy committed
11
	logging "gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log"
12 13
)

Jeromy's avatar
Jeromy committed
14
var log = logging.Logger("core/commands")
Matt Bell's avatar
Matt Bell committed
15

16 17 18 19
const (
	ApiOption = "api"
)

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

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

36
DATA STRUCTURE COMMANDS
37

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

42
ADVANCED COMMANDS
43

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

52
NETWORK COMMANDS
53

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

61
TOOL COMMANDS
62

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

Use 'ipfs <command> --help' to learn more about each command.
69 70 71 72 73

ipfs uses a repository in the local file system. By default, the repo is located
at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable:

    export IPFS_PATH=/path/to/ipfsrepo
74
`,
75
	},
76
	Options: []cmds.Option{
77 78 79 80 81
		cmds.StringOption("config", "c", "Path to the configuration file to use."),
		cmds.BoolOption("debug", "D", "Operate in debug mode."),
		cmds.BoolOption("help", "Show the full command help text."),
		cmds.BoolOption("h", "Show a short version of the command help text."),
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon."),
82
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
83
	},
84 85
}

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

89
var rootSubcommands = map[string]*cmds.Command{
90 91 92 93
	"add":       AddCmd,
	"block":     BlockCmd,
	"bootstrap": BootstrapCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
94
	"commands":  CommandsDaemonCmd,
95
	"config":    ConfigCmd,
96
	"dht":       DhtCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
97
	"diag":      DiagCmd,
98
	"dns":       DNSCmd,
Jeromy's avatar
Jeromy committed
99
	"files":     files.FilesCmd,
Matt Bell's avatar
Matt Bell committed
100
	"get":       GetCmd,
101 102 103 104 105
	"id":        IDCmd,
	"log":       LogCmd,
	"ls":        LsCmd,
	"mount":     MountCmd,
	"name":      NameCmd,
106
	"object":    ocmd.ObjectCmd,
107
	"pin":       PinCmd,
108
	"ping":      PingCmd,
109
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
110
	"repo":      RepoCmd,
111
	"resolve":   ResolveCmd,
Jeromy's avatar
Jeromy committed
112
	"stats":     StatsCmd,
113
	"swarm":     SwarmCmd,
Jeromy's avatar
Jeromy committed
114
	"tar":       TarCmd,
rht's avatar
rht committed
115
	"tour":      tourCmd,
116
	"file":      unixfs.UnixFSCmd,
Jeromy's avatar
Jeromy committed
117
	"update":    ExternalBinary(),
118
	"version":   VersionCmd,
119
	"bitswap":   BitswapCmd,
120
}
121 122 123 124 125 126

// RootRO is the readonly version of Root
var RootRO = &cmds.Command{}

var CommandsDaemonROCmd = CommandsCmd(RootRO)

rht's avatar
rht committed
127 128
var RefsROCmd = &cmds.Command{}

rht's avatar
rht committed
129 130 131 132 133 134 135 136
var rootROSubcommands = map[string]*cmds.Command{
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
	"cat":      CatCmd,
137
	"commands": CommandsDaemonROCmd,
138
	"dns":      DNSCmd,
139
	"get":      GetCmd,
rht's avatar
rht committed
140 141 142 143 144 145 146 147
	"ls":       LsCmd,
	"name": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"resolve": IpnsCmd,
		},
	},
	"object": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
148 149 150 151 152
			"data":  ocmd.ObjectDataCmd,
			"links": ocmd.ObjectLinksCmd,
			"get":   ocmd.ObjectGetCmd,
			"stat":  ocmd.ObjectStatCmd,
			"patch": ocmd.ObjectPatchCmd,
rht's avatar
rht committed
153 154
		},
	},
155 156
	"refs":    RefsROCmd,
	"resolve": ResolveCmd,
Lars Gierth's avatar
Lars Gierth committed
157
	"version": VersionCmd,
rht's avatar
rht committed
158 159
}

160
func init() {
rht's avatar
rht committed
161
	*RootRO = *Root
rht's avatar
rht committed
162 163 164 165 166

	// sanitize readonly refs command
	*RefsROCmd = *RefsCmd
	RefsROCmd.Subcommands = map[string]*cmds.Command{}

167
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
168
	RootRO.Subcommands = rootROSubcommands
169
}
170 171 172 173 174

type MessageOutput struct {
	Message string
}

175 176
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
177
}