root.go 6.29 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 14
	"github.com/ipfs/go-ipfs-cmdkit"
	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{
Jan Winkelmann's avatar
Jan Winkelmann committed
30
	Helptext: cmdkit.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
50
  mount         Mount an IPFS read-only mountpoint
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
	},
Jan Winkelmann's avatar
Jan Winkelmann committed
93
	Options: []cmdkit.Option{
94 95 96 97
		cmdkit.StringOption(ConfigOption, "c", "Path to the configuration file to use."),
		cmdkit.BoolOption(DebugOption, "D", "Operate in debug mode."),
		cmdkit.BoolOption(cmds.OptLongHelp, "Show the full command help text."),
		cmdkit.BoolOption(cmds.OptShortHelp, "Show a short version of the command help text."),
98
		cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon. DEPRECATED: use --offline."),
99
		cmdkit.BoolOption(OfflineOption, "Run the command offline."),
Jan Winkelmann's avatar
Jan Winkelmann committed
100
		cmdkit.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,
Overbool's avatar
Overbool committed
140
	"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,
Overbool's avatar
Overbool committed
148
	"update":    ExternalBinary(),
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

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

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

	// sanitize readonly refs command
	*RefsROCmd = *RefsCmd
Overbool's avatar
Overbool committed
204
	RefsROCmd.Subcommands = map[string]*cmds.Command{}
rht's avatar
rht committed
205

keks's avatar
keks committed
206 207 208
	// 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/)
Overbool's avatar
Overbool committed
209
	rootROSubcommands["refs"] = RefsROCmd
keks's avatar
keks committed
210

211
	Root.Subcommands = rootSubcommands
Jan Winkelmann's avatar
Jan Winkelmann committed
212

rht's avatar
rht committed
213
	RootRO.Subcommands = rootROSubcommands
214
}
215 216 217 218

type MessageOutput struct {
	Message string
}