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

import (
4
	"errors"
5

6
	cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
7
	dag "github.com/ipfs/go-ipfs/core/commands/dag"
8
	name "github.com/ipfs/go-ipfs/core/commands/name"
9
	ocmd "github.com/ipfs/go-ipfs/core/commands/object"
10
	unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
Jan Winkelmann's avatar
Jan Winkelmann committed
11

Jakub Sztandera's avatar
Jakub Sztandera committed
12 13
	cmds "github.com/ipfs/go-ipfs-cmds"
	logging "github.com/ipfs/go-log"
14 15
)

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

18 19
var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")

20
const (
21 22 23 24 25
	ConfigOption  = "config"
	DebugOption   = "debug"
	LocalOption   = "local" // DEPRECATED: use OfflineOption
	OfflineOption = "offline"
	ApiOption     = "api"
26 27
)

28
var Root = &cmds.Command{
Steven Allen's avatar
Steven Allen committed
29
	Helptext: cmds.HelpText{
Jakub Sztandera's avatar
Jakub Sztandera committed
30
		Tagline:  "Global p2p merkle-dag filesystem.",
31
		Synopsis: "ipfs [--config=<config> | -c] [--debug | -D] [--help] [-h] [--api=<api>] [--offline] [--cid-base=<base>] [--upgrade-cidv0-in-output] [--encoding=<encoding> | --enc] [--timeout=<timeout>] <command> ...",
32
		Subcommands: `
33
BASIC COMMANDS
34
  init          Initialize ipfs local configuration
35
  add <path>    Add a file to IPFS
36 37
  cat <ref>     Show IPFS object data
  get <ref>     Download IPFS objects
38 39
  ls <ref>      List links from an object
  refs <ref>    List hashes of links from an object
40

41
DATA STRUCTURE COMMANDS
42 43 44
  block         Interact with raw blocks in the datastore
  object        Interact with raw dag nodes
  files         Interact with objects as if they were a unix filesystem
slothbag's avatar
slothbag committed
45
  dag           Interact with IPLD documents (experimental)
46

47
ADVANCED COMMANDS
48
  daemon        Start a long-running daemon process
49
  mount         Mount an IPFS read-only mountpoint
50
  resolve       Resolve any type of name
51 52
  name          Publish and resolve IPNS names
  key           Create and list IPNS name keypairs
53 54 55
  dns           Resolve DNS links
  pin           Pin objects to local storage
  repo          Manipulate the IPFS repository
slothbag's avatar
slothbag committed
56
  stats         Various operational stats
Łukasz Magiera's avatar
Łukasz Magiera committed
57
  p2p           Libp2p stream mounting
58
  filestore     Manage the filestore (experimental)
59

60
NETWORK COMMANDS
61
  id            Show info about IPFS peers
62 63 64 65 66
  bootstrap     Add or remove bootstrap peers
  swarm         Manage connections to the p2p network
  dht           Query the DHT for values or peers
  ping          Measure the latency of a connection
  diag          Print diagnostics
67

68
TOOL COMMANDS
69 70 71 72
  config        Manage configuration
  version       Show ipfs version information
  update        Download and apply go-ipfs updates
  commands      List all available commands
73
  cid           Convert and discover properties of CIDs
74
  log           Manage and show logs of running daemon
75 76

Use 'ipfs <command> --help' to learn more about each command.
77

78 79 80
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:
81

82
  export IPFS_PATH=/path/to/ipfsrepo
83 84 85

EXIT STATUS

Richard Littauer's avatar
Richard Littauer committed
86
The CLI will exit with one of the following values:
87 88 89

0     Successful execution.
1     Failed executions.
90
`,
91
	},
Steven Allen's avatar
Steven Allen committed
92 93 94 95 96 97 98 99
	Options: []cmds.Option{
		cmds.StringOption(ConfigOption, "c", "Path to the configuration file to use."),
		cmds.BoolOption(DebugOption, "D", "Operate in debug mode."),
		cmds.BoolOption(cmds.OptLongHelp, "Show the full command help text."),
		cmds.BoolOption(cmds.OptShortHelp, "Show a short version of the command help text."),
		cmds.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon. DEPRECATED: use --offline."),
		cmds.BoolOption(OfflineOption, "Run the command offline."),
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
100 101

		// global options, added to every command
102
		cmdenv.OptionCidBase,
103
		cmdenv.OptionUpgradeCidV0InOutput,
104

105 106 107
		cmds.OptionEncodingType,
		cmds.OptionStreamChannels,
		cmds.OptionTimeout,
108
	},
109 110
}

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

114
var rootSubcommands = map[string]*cmds.Command{
115
	"add":       AddCmd,
Jan Winkelmann's avatar
Jan Winkelmann committed
116
	"bitswap":   BitswapCmd,
117 118
	"block":     BlockCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
119
	"commands":  CommandsDaemonCmd,
120
	"files":     FilesCmd,
Jan Winkelmann's avatar
Jan Winkelmann committed
121 122 123 124 125
	"filestore": FileStoreCmd,
	"get":       GetCmd,
	"pubsub":    PubsubCmd,
	"repo":      RepoCmd,
	"stats":     StatsCmd,
Overbool's avatar
Overbool committed
126
	"bootstrap": BootstrapCmd,
127
	"config":    ConfigCmd,
Overbool's avatar
Overbool committed
128
	"dag":       dag.DagCmd,
Overbool's avatar
Overbool committed
129
	"dht":       DhtCmd,
130
	"diag":      DiagCmd,
131
	"dns":       DNSCmd,
132
	"id":        IDCmd,
133
	"key":       KeyCmd,
134
	"log":       LogCmd,
135
	"ls":        LsCmd,
136
	"mount":     MountCmd,
137
	"name":      name.NameCmd,
138
	"object":    ocmd.ObjectCmd,
Overbool's avatar
Overbool committed
139
	"pin":       PinCmd,
Overbool's avatar
Overbool committed
140
	"ping":      PingCmd,
Overbool's avatar
Overbool committed
141
	"p2p":       P2PCmd,
Overbool's avatar
Overbool committed
142
	"refs":      RefsCmd,
143
	"resolve":   ResolveCmd,
144
	"swarm":     SwarmCmd,
145
	"tar":       TarCmd,
Overbool's avatar
Overbool committed
146
	"file":      unixfs.UnixFSCmd,
Overbool's avatar
Overbool committed
147
	"update":    ExternalBinary(),
148
	"urlstore":  urlStoreCmd,
149
	"version":   VersionCmd,
150
	"shutdown":  daemonShutdownCmd,
151
	"cid":       CidCmd,
152
}
153 154 155 156 157 158

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

Overbool's avatar
Overbool committed
159
// RefsROCmd is `ipfs refs` command
Overbool's avatar
Overbool committed
160
var RefsROCmd = &cmds.Command{}
rht's avatar
rht committed
161

162 163 164
// VersionROCmd is `ipfs version` command (without deps).
var VersionROCmd = &cmds.Command{}

rht's avatar
rht committed
165
var rootROSubcommands = map[string]*cmds.Command{
Jan Winkelmann's avatar
Jan Winkelmann committed
166 167
	"commands": CommandsDaemonROCmd,
	"cat":      CatCmd,
rht's avatar
rht committed
168 169 170 171 172 173
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
Jan Winkelmann's avatar
Jan Winkelmann committed
174
	"get": GetCmd,
175
	"dns": DNSCmd,
176
	"ls":  LsCmd,
Overbool's avatar
Overbool committed
177
	"name": {
178 179
		Subcommands: map[string]*cmds.Command{
			"resolve": name.IpnsCmd,
rht's avatar
rht committed
180
		},
181
	},
182 183
	"object": {
		Subcommands: map[string]*cmds.Command{
184 185 186 187
			"data":  ocmd.ObjectDataCmd,
			"links": ocmd.ObjectLinksCmd,
			"get":   ocmd.ObjectGetCmd,
			"stat":  ocmd.ObjectStatCmd,
rht's avatar
rht committed
188
		},
Overbool's avatar
Overbool committed
189
	},
Overbool's avatar
Overbool committed
190 191
	"dag": {
		Subcommands: map[string]*cmds.Command{
Łukasz Magiera's avatar
Łukasz Magiera committed
192 193
			"get":     dag.DagGetCmd,
			"resolve": dag.DagResolveCmd,
jbenet's avatar
jbenet committed
194
		},
Overbool's avatar
Overbool committed
195
	},
196
	"resolve": ResolveCmd,
rht's avatar
rht committed
197 198
}

199
func init() {
200
	Root.ProcessHelp()
rht's avatar
rht committed
201
	*RootRO = *Root
rht's avatar
rht committed
202

keks's avatar
keks committed
203 204 205
	// this was in the big map definition above before,
	// but if we leave it there lgc.NewCommand will be executed
	// before the value is updated (:/sanitize readonly refs command/)
206 207 208 209

	// sanitize readonly refs command
	*RefsROCmd = *RefsCmd
	RefsROCmd.Subcommands = map[string]*cmds.Command{}
Overbool's avatar
Overbool committed
210
	rootROSubcommands["refs"] = RefsROCmd
keks's avatar
keks committed
211

212 213 214 215
	// sanitize readonly version command (no need to expose precise deps)
	*VersionROCmd = *VersionCmd
	VersionROCmd.Subcommands = map[string]*cmds.Command{}
	rootROSubcommands["version"] = VersionROCmd
Jan Winkelmann's avatar
Jan Winkelmann committed
216

217
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
218
	RootRO.Subcommands = rootROSubcommands
219
}
220 221 222 223

type MessageOutput struct {
	Message string
}