root.go 4.84 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"
Jeromy's avatar
Jeromy committed
11
	logging "gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/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 20
type TestOutput struct {
	Foo string
	Bar int
}

21 22 23 24
const (
	ApiOption = "api"
)

25
var Root = &cmds.Command{
26
	Helptext: cmds.HelpText{
rht's avatar
rht committed
27
		Tagline: "Global p2p merkle-dag filesystem.",
28 29 30
		Synopsis: `
ipfs [<flags>] <command> [<arg>] ...
`,
31
		ShortDescription: `
32
BASIC COMMANDS
33

Markus Amalthea Magnuson's avatar
Markus Amalthea Magnuson committed
34
    init          Initialize ipfs local configuration
Richard Littauer's avatar
Richard Littauer committed
35
    add <path>    Add a file to ipfs
36
    cat <ref>     Show ipfs object data
37
    get <ref>     Download ipfs objects
38
    ls <ref>      List links from an object
39
    refs <ref>    List hashes of links from an object
40

41
DATA STRUCTURE COMMANDS
42

43 44
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
45
    files         Interact with objects as if they were a unix filesystem
46
    file          Interact with Unix filesystem objects
47

48
ADVANCED COMMANDS
49

50
    daemon        Start a long-running daemon process
51
    mount         Mount an ipfs read-only mountpoint
52
    resolve       Resolve any type of name
53
    name          Publish or resolve IPNS names
54
    dns           Resolve DNS links
55
    pin           Pin objects to local storage
56
    repo gc       Garbage collect unpinned objects
57

58
NETWORK COMMANDS
59

60
    id            Show info about ipfs peers
61
    bootstrap     Add or remove bootstrap peers
62
    swarm         Manage connections to the p2p network
Richard Littauer's avatar
Richard Littauer committed
63
    dht           Query the DHT for values or peers
64
    ping          Measure the latency of a connection
65
    diag          Print diagnostics
66

67
TOOL COMMANDS
68

69 70 71 72
    config        Manage configuration
    version       Show ipfs version information
    update        Download and apply go-ipfs updates
    commands      List all available commands
73 74

Use 'ipfs <command> --help' to learn more about each command.
75 76 77 78 79

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:

    export IPFS_PATH=/path/to/ipfsrepo
80
`,
81
	},
82
	Options: []cmds.Option{
83 84 85 86 87
		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."),
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
	"dht":       DhtCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
103
	"diag":      DiagCmd,
104
	"dns":       DNSCmd,
Jeromy's avatar
Jeromy committed
105
	"files":     files.FilesCmd,
Matt Bell's avatar
Matt Bell committed
106
	"get":       GetCmd,
107 108 109 110 111
	"id":        IDCmd,
	"log":       LogCmd,
	"ls":        LsCmd,
	"mount":     MountCmd,
	"name":      NameCmd,
112
	"object":    ocmd.ObjectCmd,
113
	"pin":       PinCmd,
114
	"ping":      PingCmd,
115
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
116
	"repo":      RepoCmd,
117
	"resolve":   ResolveCmd,
Jeromy's avatar
Jeromy committed
118
	"stats":     StatsCmd,
119
	"swarm":     SwarmCmd,
Jeromy's avatar
Jeromy committed
120
	"tar":       TarCmd,
rht's avatar
rht committed
121
	"tour":      tourCmd,
122
	"file":      unixfs.UnixFSCmd,
Jeromy's avatar
Jeromy committed
123
	"update":    ExternalBinary(),
124
	"version":   VersionCmd,
125
	"bitswap":   BitswapCmd,
126
}
127 128 129 130 131 132

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

rht's avatar
rht committed
133 134
var RefsROCmd = &cmds.Command{}

rht's avatar
rht committed
135 136 137 138 139 140 141 142
var rootROSubcommands = map[string]*cmds.Command{
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
	"cat":      CatCmd,
143
	"commands": CommandsDaemonROCmd,
144
	"dns":      DNSCmd,
145
	"get":      GetCmd,
rht's avatar
rht committed
146 147 148 149 150 151 152 153
	"ls":       LsCmd,
	"name": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"resolve": IpnsCmd,
		},
	},
	"object": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
154 155 156 157 158
			"data":  ocmd.ObjectDataCmd,
			"links": ocmd.ObjectLinksCmd,
			"get":   ocmd.ObjectGetCmd,
			"stat":  ocmd.ObjectStatCmd,
			"patch": ocmd.ObjectPatchCmd,
rht's avatar
rht committed
159 160
		},
	},
161 162
	"refs":    RefsROCmd,
	"resolve": ResolveCmd,
Lars Gierth's avatar
Lars Gierth committed
163
	"version": VersionCmd,
rht's avatar
rht committed
164 165
}

166
func init() {
rht's avatar
rht committed
167
	*RootRO = *Root
rht's avatar
rht committed
168 169 170 171 172

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

173
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
174
	RootRO.Subcommands = rootROSubcommands
175
}
176 177 178 179 180

type MessageOutput struct {
	Message string
}

181 182
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
183
}