github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/core/commands/root.go (about) 1 package commands 2 3 import ( 4 "io" 5 "strings" 6 7 cmds "github.com/ipfs/go-ipfs/commands" 8 unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs" 9 evlog "github.com/ipfs/go-ipfs/thirdparty/eventlog" 10 ) 11 12 var log = evlog.Logger("core/commands") 13 14 type TestOutput struct { 15 Foo string 16 Bar int 17 } 18 19 const ( 20 ApiOption = "api" 21 ) 22 23 var Root = &cmds.Command{ 24 Helptext: cmds.HelpText{ 25 Tagline: "global p2p merkle-dag filesystem", 26 Synopsis: ` 27 ipfs [<flags>] <command> [<arg>] ... 28 `, 29 ShortDescription: ` 30 BASIC COMMANDS 31 32 init Initialize ipfs local configuration 33 add <path> Add an object to ipfs 34 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 block Interact with raw blocks in the datastore 42 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 swarm Manage connections to the p2p network 60 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 config Manage configuration 67 version Show ipfs version information 68 update Download and apply go-ipfs updates 69 commands List all available commands 70 71 Use 'ipfs <command> --help' to learn more about each command. 72 `, 73 }, 74 Options: []cmds.Option{ 75 cmds.StringOption("config", "c", "Path to the configuration file to use"), 76 cmds.BoolOption("debug", "D", "Operate in debug mode"), 77 cmds.BoolOption("help", "Show the full command help text"), 78 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 84 // commandsDaemonCmd is the "ipfs commands" command for daemon 85 var CommandsDaemonCmd = CommandsCmd(Root) 86 87 var rootSubcommands = map[string]*cmds.Command{ 88 "add": AddCmd, 89 "block": BlockCmd, 90 "bootstrap": BootstrapCmd, 91 "cat": CatCmd, 92 "commands": CommandsDaemonCmd, 93 "config": ConfigCmd, 94 "dht": DhtCmd, 95 "diag": DiagCmd, 96 "dns": DNSCmd, 97 "get": GetCmd, 98 "id": IDCmd, 99 "log": LogCmd, 100 "ls": LsCmd, 101 "mount": MountCmd, 102 "name": NameCmd, 103 "object": ObjectCmd, 104 "pin": PinCmd, 105 "ping": PingCmd, 106 "refs": RefsCmd, 107 "repo": RepoCmd, 108 "resolve": ResolveCmd, 109 "stats": StatsCmd, 110 "swarm": SwarmCmd, 111 "tour": tourCmd, 112 "file": unixfs.UnixFSCmd, 113 "update": UpdateCmd, 114 "version": VersionCmd, 115 "bitswap": BitswapCmd, 116 } 117 118 // RootRO is the readonly version of Root 119 var RootRO = &cmds.Command{} 120 121 var CommandsDaemonROCmd = CommandsCmd(RootRO) 122 123 var RefsROCmd = &cmds.Command{} 124 125 var rootROSubcommands = map[string]*cmds.Command{ 126 "block": &cmds.Command{ 127 Subcommands: map[string]*cmds.Command{ 128 "stat": blockStatCmd, 129 "get": blockGetCmd, 130 }, 131 }, 132 "cat": CatCmd, 133 "commands": CommandsDaemonROCmd, 134 "ls": LsCmd, 135 "name": &cmds.Command{ 136 Subcommands: map[string]*cmds.Command{ 137 "resolve": IpnsCmd, 138 }, 139 }, 140 "object": &cmds.Command{ 141 Subcommands: map[string]*cmds.Command{ 142 "data": objectDataCmd, 143 "links": objectLinksCmd, 144 "get": objectGetCmd, 145 "stat": objectStatCmd, 146 }, 147 }, 148 "refs": RefsROCmd, 149 //"resolve": ResolveCmd, 150 } 151 152 func init() { 153 *RootRO = *Root 154 155 // sanitize readonly refs command 156 *RefsROCmd = *RefsCmd 157 RefsROCmd.Subcommands = map[string]*cmds.Command{} 158 159 Root.Subcommands = rootSubcommands 160 RootRO.Subcommands = rootROSubcommands 161 } 162 163 type MessageOutput struct { 164 Message string 165 } 166 167 func MessageTextMarshaler(res cmds.Response) (io.Reader, error) { 168 return strings.NewReader(res.Output().(*MessageOutput).Message), nil 169 }