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

import (
4 5 6
	"io"
	"strings"

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

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

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

21
var Root = &cmds.Command{
22
	Helptext: cmds.HelpText{
Jakub Sztandera's avatar
Jakub Sztandera committed
23 24
		Tagline:  "Global p2p merkle-dag filesystem.",
		Synopsis: "ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...",
25
		Subcommands: `
26
BASIC COMMANDS
27
  init          Initialize ipfs local configuration
28
  add <path>    Add a file to IPFS
29 30
  cat <ref>     Show IPFS object data
  get <ref>     Download IPFS objects
31 32
  ls <ref>      List links from an object
  refs <ref>    List hashes of links from an object
33

34
DATA STRUCTURE COMMANDS
35 36 37
  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
38
  dag           Interact with IPLD documents (experimental)
39

40
ADVANCED COMMANDS
41
  daemon        Start a long-running daemon process
42
  mount         Mount an IPFS read-only mountpoint
43
  resolve       Resolve any type of name
44 45
  name          Publish and resolve IPNS names
  key           Create and list IPNS name keypairs
46 47 48
  dns           Resolve DNS links
  pin           Pin objects to local storage
  repo          Manipulate the IPFS repository
slothbag's avatar
slothbag committed
49
  stats         Various operational stats
50
  ptp           Libp2p stream mounting
51
  filestore     Manage the filestore (experimental)
52

53
NETWORK COMMANDS
54
  id            Show info about IPFS peers
55 56 57 58 59
  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
60

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

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

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:

72
  export IPFS_PATH=/path/to/ipfsrepo
73 74 75

EXIT STATUS

Richard Littauer's avatar
Richard Littauer committed
76
The CLI will exit with one of the following values:
77 78 79

0     Successful execution.
1     Failed executions.
80
`,
81
	},
82
	Options: []cmds.Option{
83
		cmds.StringOption("config", "c", "Path to the configuration file to use."),
Richard Littauer's avatar
Richard Littauer committed
84 85 86 87
		cmds.BoolOption("debug", "D", "Operate in debug mode.").Default(false),
		cmds.BoolOption("help", "Show the full command help text.").Default(false),
		cmds.BoolOption("h", "Show a short version of the command help text.").Default(false),
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon.").Default(false),
88
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
89
	},
90 91
}

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

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

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

rht's avatar
rht committed
139 140
var RefsROCmd = &cmds.Command{}

rht's avatar
rht committed
141 142 143 144 145 146 147 148
var rootROSubcommands = map[string]*cmds.Command{
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
	"cat":      CatCmd,
149
	"commands": CommandsDaemonROCmd,
150
	"dns":      DNSCmd,
151
	"get":      GetCmd,
rht's avatar
rht committed
152 153 154 155 156 157 158 159
	"ls":       LsCmd,
	"name": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"resolve": IpnsCmd,
		},
	},
	"object": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
160 161 162 163 164
			"data":  ocmd.ObjectDataCmd,
			"links": ocmd.ObjectLinksCmd,
			"get":   ocmd.ObjectGetCmd,
			"stat":  ocmd.ObjectStatCmd,
			"patch": ocmd.ObjectPatchCmd,
rht's avatar
rht committed
165 166
		},
	},
167 168 169 170 171
	"dag": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"get": dag.DagGetCmd,
		},
	},
172 173
	"refs":    RefsROCmd,
	"resolve": ResolveCmd,
174
	"version": VersionCmd,
rht's avatar
rht committed
175 176
}

177
func init() {
178
	Root.ProcessHelp()
rht's avatar
rht committed
179
	*RootRO = *Root
rht's avatar
rht committed
180 181 182 183 184

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

185
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
186
	RootRO.Subcommands = rootROSubcommands
187
}
188 189 190 191 192

type MessageOutput struct {
	Message string
}

193 194
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
195
}