root.go 6.64 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
	"github.com/ipfs/go-ipfs/core/commands/pin"
11
	unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
Jan Winkelmann's avatar
Jan Winkelmann committed
12

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

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

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

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

29
var Root = &cmds.Command{
Steven Allen's avatar
Steven Allen committed
30
	Helptext: cmds.HelpText{
Jakub Sztandera's avatar
Jakub Sztandera committed
31
		Tagline:  "Global p2p merkle-dag filesystem.",
32
		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> ...",
33
		Subcommands: `
34
BASIC COMMANDS
35
  init          Initialize ipfs local configuration
36
  add <path>    Add a file to IPFS
37 38
  cat <ref>     Show IPFS object data
  get <ref>     Download IPFS objects
39 40
  ls <ref>      List links from an object
  refs <ref>    List hashes of links from an object
41

42
DATA STRUCTURE COMMANDS
43 44 45
  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
46
  dag           Interact with IPLD documents (experimental)
47

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

61
NETWORK COMMANDS
62
  id            Show info about IPFS peers
63 64 65 66 67
  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
68

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

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

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

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

EXIT STATUS

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

0     Successful execution.
1     Failed executions.
91
`,
92
	},
Steven Allen's avatar
Steven Allen committed
93 94 95 96 97 98 99 100
	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)"),
101 102

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

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

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

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

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

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

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

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

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

keks's avatar
keks committed
205 206 207
	// 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/)
208 209 210 211

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

214 215 216 217
	// 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
218

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

type MessageOutput struct {
	Message string
}