root.go 6.28 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

Hector Sanjuan's avatar
Hector Sanjuan committed
12
	cmds "gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
Steven Allen's avatar
Steven Allen committed
13
	logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
14
	"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
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 32
		Tagline:  "Global p2p merkle-dag filesystem.",
		Synopsis: "ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <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 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
	},
Jan Winkelmann's avatar
Jan Winkelmann committed
92
	Options: []cmdkit.Option{
93 94 95 96
		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."),
97
		cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon. DEPRECATED: use --offline."),
98
		cmdkit.BoolOption(OfflineOption, "Run the command offline."),
Jan Winkelmann's avatar
Jan Winkelmann committed
99
		cmdkit.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

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

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

	// sanitize readonly refs command
	*RefsROCmd = *RefsCmd
Overbool's avatar
Overbool committed
203
	RefsROCmd.Subcommands = map[string]*cmds.Command{}
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/)
Overbool's avatar
Overbool committed
208
	rootROSubcommands["refs"] = RefsROCmd
keks's avatar
keks committed
209

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

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

type MessageOutput struct {
	Message string
}