root.go 4.31 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
	Options: []cmds.Option{
75 76
		cmds.StringOption("config", "c", "Path to the configuration file to use"),
		cmds.BoolOption("debug", "D", "Operate in debug mode"),
77 78
		cmds.BoolOption("help", "Show the full command help text"),
		cmds.BoolOption("h", "Show a short version of the command help text"),
79
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
80
		cmds.StringOption(ApiOption, "Overrides the routing option (dht, supernode)"),
81
	},
82 83
}

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

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

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

var CommandsDaemonROCmd = CommandsCmd(RootRO)

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

rht's avatar
rht committed
126 127 128 129 130 131 132 133
var rootROSubcommands = map[string]*cmds.Command{
	"block": &cmds.Command{
		Subcommands: map[string]*cmds.Command{
			"stat": blockStatCmd,
			"get":  blockGetCmd,
		},
	},
	"cat":      CatCmd,
134
	"commands": CommandsDaemonROCmd,
rht's avatar
rht committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148
	"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,
		},
	},
rht's avatar
rht committed
149
	"refs": RefsROCmd,
rht's avatar
rht committed
150 151 152
	//"resolve": ResolveCmd,
}

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

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

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

type MessageOutput struct {
	Message string
}

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