root.go 4.76 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 "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/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{
27 28 29 30
		Tagline: "global p2p merkle-dag filesystem",
		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
    file          Interact with Unix filesystem objects
46

47
ADVANCED COMMANDS
48

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

57
NETWORK COMMANDS
58

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

66
TOOL COMMANDS
67

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

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

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
79
`,
80
	},
81
	Options: []cmds.Option{
82 83
		cmds.StringOption("config", "c", "Path to the configuration file to use"),
		cmds.BoolOption("debug", "D", "Operate in debug mode"),
84 85
		cmds.BoolOption("help", "Show the full command help text"),
		cmds.BoolOption("h", "Show a short version of the command help text"),
86
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
87
		cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
88
	},
89 90
}

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

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

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

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

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

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

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

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

type MessageOutput struct {
	Message string
}

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