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

import (
4 5 6
	"io"
	"strings"

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

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

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

20
var Root = &cmds.Command{
21
	Helptext: cmds.HelpText{
rht's avatar
rht committed
22
		Tagline: "Global p2p merkle-dag filesystem.",
23 24 25
		Synopsis: `
ipfs [<flags>] <command> [<arg>] ...
`,
26
		Subcommands: `
27
BASIC COMMANDS
28 29 30 31 32 33
  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
34

35
DATA STRUCTURE COMMANDS
36 37 38
  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
39

40
ADVANCED COMMANDS
41 42 43 44 45 46 47
  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
48

49
NETWORK COMMANDS
50 51 52 53 54 55
  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
56

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

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

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:

68
  export IPFS_PATH=/path/to/ipfsrepo
69
`,
70
	},
71
	Options: []cmds.Option{
72 73 74 75 76
		cmds.StringOption("config", "c", "Path to the configuration file to use."),
		cmds.BoolOption("debug", "D", "Operate in debug mode."),
		cmds.BoolOption("help", "Show the full command help text."),
		cmds.BoolOption("h", "Show a short version of the command help text."),
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon."),
77
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
78
	},
79 80
}

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

84
var rootSubcommands = map[string]*cmds.Command{
85 86 87 88
	"add":       AddCmd,
	"block":     BlockCmd,
	"bootstrap": BootstrapCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
89
	"commands":  CommandsDaemonCmd,
90
	"config":    ConfigCmd,
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,
104
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
105
	"repo":      RepoCmd,
106
	"resolve":   ResolveCmd,
Jeromy's avatar
Jeromy committed
107
	"stats":     StatsCmd,
108
	"swarm":     SwarmCmd,
Jeromy's avatar
Jeromy committed
109
	"tar":       TarCmd,
rht's avatar
rht committed
110
	"tour":      tourCmd,
111
	"file":      unixfs.UnixFSCmd,
Jeromy's avatar
Jeromy committed
112
	"update":    ExternalBinary(),
113
	"version":   VersionCmd,
114
	"bitswap":   BitswapCmd,
115
}
116 117 118 119 120 121

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

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

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

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

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

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

type MessageOutput struct {
	Message string
}

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