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

import (
4 5 6
	"io"
	"strings"

7
	cmds "github.com/ipfs/go-ipfs/commands"
8
	unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
Jeromy's avatar
Jeromy committed
9
	logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
10 11
)

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

14 15 16 17 18
type TestOutput struct {
	Foo string
	Bar int
}

19 20 21 22
const (
	ApiOption = "api"
)

23
var Root = &cmds.Command{
24
	Helptext: cmds.HelpText{
25 26 27 28
		Tagline: "global p2p merkle-dag filesystem",
		Synopsis: `
ipfs [<flags>] <command> [<arg>] ...
`,
29
		ShortDescription: `
30
BASIC COMMANDS
31

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

39
DATA STRUCTURE COMMANDS
40

41 42
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
43
    file          Interact with Unix filesystem objects
44

45
ADVANCED COMMANDS
46

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

55
NETWORK COMMANDS
56

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

64
TOOL COMMANDS
65

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

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

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

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

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

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

rht's avatar
rht committed
129 130
var RefsROCmd = &cmds.Command{}

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

161
func init() {
rht's avatar
rht committed
162
	*RootRO = *Root
rht's avatar
rht committed
163 164 165 166 167

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

168
	Root.Subcommands = rootSubcommands
rht's avatar
rht committed
169
	RootRO.Subcommands = rootROSubcommands
170
}
171 172 173 174 175

type MessageOutput struct {
	Message string
}

176 177
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
178
}