root.go 4.94 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 28 29 30 31 32
  init          Initialize ipfs local configuration
  add <path>    Add a file to ipfs
  cat <ref>     Show ipfs object data
  get <ref>     Download ipfs objects
  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
38

39
ADVANCED COMMANDS
40 41 42 43 44 45 46
  daemon        Start a long-running daemon process
  mount         Mount an ipfs read-only mountpoint
  resolve       Resolve any type of name
  name          Publish or resolve IPNS names
  dns           Resolve DNS links
  pin           Pin objects to local storage
  repo          Manipulate the IPFS repository
47

48
NETWORK COMMANDS
49 50 51 52 53 54
  id            Show info about ipfs peers
  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
55

56
TOOL COMMANDS
57 58 59 60
  config        Manage configuration
  version       Show ipfs version information
  update        Download and apply go-ipfs updates
  commands      List all available commands
61 62

Use 'ipfs <command> --help' to learn more about each command.
63 64 65 66

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:

67
  export IPFS_PATH=/path/to/ipfsrepo
68
`,
69
	},
70
	Options: []cmds.Option{
71
		cmds.StringOption("config", "c", "Path to the configuration file to use."),
Richard Littauer's avatar
Richard Littauer committed
72 73 74 75
		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),
76
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
77
	},
78 79
}

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

83
var rootSubcommands = map[string]*cmds.Command{
84 85 86 87
	"add":       AddCmd,
	"block":     BlockCmd,
	"bootstrap": BootstrapCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
88
	"commands":  CommandsDaemonCmd,
89
	"config":    ConfigCmd,
90
	"dag":       dag.DagCmd,
91
	"dht":       DhtCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
92
	"diag":      DiagCmd,
93
	"dns":       DNSCmd,
Jeromy's avatar
Jeromy committed
94
	"files":     files.FilesCmd,
Matt Bell's avatar
Matt Bell committed
95
	"get":       GetCmd,
96 97 98 99 100
	"id":        IDCmd,
	"log":       LogCmd,
	"ls":        LsCmd,
	"mount":     MountCmd,
	"name":      NameCmd,
101
	"object":    ocmd.ObjectCmd,
102
	"pin":       PinCmd,
103
	"ping":      PingCmd,
Jeromy's avatar
Jeromy committed
104
	"pubsub":    PubsubCmd,
105
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
106
	"repo":      RepoCmd,
107
	"resolve":   ResolveCmd,
Jeromy's avatar
Jeromy committed
108
	"stats":     StatsCmd,
109
	"swarm":     SwarmCmd,
Jeromy's avatar
Jeromy committed
110
	"tar":       TarCmd,
rht's avatar
rht committed
111
	"tour":      tourCmd,
112
	"file":      unixfs.UnixFSCmd,
Jeromy's avatar
Jeromy committed
113
	"update":    ExternalBinary(),
114
	"version":   VersionCmd,
115
	"bitswap":   BitswapCmd,
116
}
117 118 119 120 121 122

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

rht's avatar
rht committed
123 124
var RefsROCmd = &cmds.Command{}

rht's avatar
rht committed
125 126 127 128 129 130 131 132
var rootROSubcommands = map[string]*cmds.Command{
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
	"cat":      CatCmd,
133
	"commands": CommandsDaemonROCmd,
134
	"dns":      DNSCmd,
135
	"get":      GetCmd,
rht's avatar
rht committed
136 137 138 139 140 141 142 143
	"ls":       LsCmd,
	"name": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"resolve": IpnsCmd,
		},
	},
	"object": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
144 145 146 147 148
			"data":  ocmd.ObjectDataCmd,
			"links": ocmd.ObjectLinksCmd,
			"get":   ocmd.ObjectGetCmd,
			"stat":  ocmd.ObjectStatCmd,
			"patch": ocmd.ObjectPatchCmd,
rht's avatar
rht committed
149 150
		},
	},
151 152
	"refs":    RefsROCmd,
	"resolve": ResolveCmd,
Lars Gierth's avatar
Lars Gierth committed
153
	"version": VersionCmd,
rht's avatar
rht committed
154 155
}

156
func init() {
157
	Root.ProcessHelp()
rht's avatar
rht committed
158
	*RootRO = *Root
rht's avatar
rht committed
159 160 161 162 163

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

164
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
165
	RootRO.Subcommands = rootROSubcommands
166
}
167 168 169 170 171

type MessageOutput struct {
	Message string
}

172 173
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
174
}