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

import (
4 5 6
	"io"
	"strings"

7
	cmds "github.com/jbenet/go-ipfs/commands"
Matt Bell's avatar
Matt Bell committed
8
	u "github.com/jbenet/go-ipfs/util"
9 10
)

Matt Bell's avatar
Matt Bell committed
11 12
var log = u.Logger("core/commands")

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

var Root = &cmds.Command{
19
	Helptext: cmds.HelpText{
20 21 22 23
		Tagline: "global p2p merkle-dag filesystem",
		Synopsis: `
ipfs [<flags>] <command> [<arg>] ...
`,
24 25
		ShortDescription: `
Basic commands:
26

Markus Amalthea Magnuson's avatar
Markus Amalthea Magnuson committed
27
    init          Initialize ipfs local configuration
28 29 30
    add <path>    Add an object to ipfs
    cat <ref>     Show ipfs object data
    ls <ref>      List links from an object
31
    refs <ref>    List hashes of links from an object
32 33 34

Tool commands:

35 36 37 38
    config        Manage configuration
    update        Download and apply go-ipfs updates
    version       Show ipfs version information
    commands      List all available commands
Jeromy's avatar
Jeromy committed
39
    id            Show info about ipfs peers
40 41 42 43
    pin           Pin objects to local storage
    name          Publish or resolve IPNS names
    log           Change the logging level

44 45
Advanced Commands:

46
    daemon        Start a long-running daemon process
47 48
    mount         Mount an ipfs read-only mountpoint
    diag          Print diagnostics
49

50 51 52 53 54 55
Network commands:

    swarm         Manage connections to the p2p network
    bootstrap     Add or remove bootstrap peers
    ping          Measure the latency of a connection

56 57 58 59
Plumbing commands:

    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
60 61

Use 'ipfs <command> --help' to learn more about each command.
62
`,
63
	},
64
	Options: []cmds.Option{
65 66
		cmds.StringOption("config", "c", "Path to the configuration file to use"),
		cmds.BoolOption("debug", "D", "Operate in debug mode"),
67 68
		cmds.BoolOption("help", "Show the full command help text"),
		cmds.BoolOption("h", "Show a short version of the command help text"),
69
		cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
70
	},
71 72
}

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

76
var rootSubcommands = map[string]*cmds.Command{
77 78 79 80
	"add":       AddCmd,
	"block":     BlockCmd,
	"bootstrap": BootstrapCmd,
	"cat":       CatCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
81
	"commands":  CommandsDaemonCmd,
82
	"config":    ConfigCmd,
83
	"dht":       DhtCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
84
	"diag":      DiagCmd,
85 86 87 88 89 90 91
	"id":        IDCmd,
	"log":       LogCmd,
	"ls":        LsCmd,
	"mount":     MountCmd,
	"name":      NameCmd,
	"object":    ObjectCmd,
	"pin":       PinCmd,
92
	"ping":      PingCmd,
93
	"refs":      RefsCmd,
Jeromy's avatar
Jeromy committed
94
	"repo":      RepoCmd,
95
	"swarm":     SwarmCmd,
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
96
	"update":    UpdateCmd,
97
	"version":   VersionCmd,
98
}
99 100

func init() {
101
	Root.Subcommands = rootSubcommands
102
}
103 104 105 106 107

type MessageOutput struct {
	Message string
}

108 109
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
	return strings.NewReader(res.Output().(*MessageOutput).Message), nil
110
}