mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-24 18:37:32 +08:00
230 lines
6.6 KiB
Go
230 lines
6.6 KiB
Go
package commands
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
|
|
oldcmds "github.com/ipfs/go-ipfs/commands"
|
|
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
|
dag "github.com/ipfs/go-ipfs/core/commands/dag"
|
|
e "github.com/ipfs/go-ipfs/core/commands/e"
|
|
name "github.com/ipfs/go-ipfs/core/commands/name"
|
|
ocmd "github.com/ipfs/go-ipfs/core/commands/object"
|
|
unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
|
|
|
|
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
|
|
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
|
|
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
|
)
|
|
|
|
var log = logging.Logger("core/commands")
|
|
|
|
var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")
|
|
|
|
const (
|
|
ConfigOption = "config"
|
|
DebugOption = "debug"
|
|
LocalOption = "local"
|
|
ApiOption = "api"
|
|
)
|
|
|
|
var Root = &cmds.Command{
|
|
Helptext: cmdkit.HelpText{
|
|
Tagline: "Global p2p merkle-dag filesystem.",
|
|
Synopsis: "ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...",
|
|
Subcommands: `
|
|
BASIC COMMANDS
|
|
init Initialize ipfs local configuration
|
|
add <path> Add a file to IPFS
|
|
cat <ref> Show IPFS object data
|
|
get <ref> Download IPFS objects
|
|
ls <ref> List links from an object
|
|
refs <ref> List hashes of links from an object
|
|
|
|
DATA STRUCTURE COMMANDS
|
|
block Interact with raw blocks in the datastore
|
|
object Interact with raw dag nodes
|
|
files Interact with objects as if they were a unix filesystem
|
|
dag Interact with IPLD documents (experimental)
|
|
|
|
ADVANCED COMMANDS
|
|
daemon Start a long-running daemon process
|
|
mount Mount an IPFS read-only mountpoint
|
|
resolve Resolve any type of name
|
|
name Publish and resolve IPNS names
|
|
key Create and list IPNS name keypairs
|
|
dns Resolve DNS links
|
|
pin Pin objects to local storage
|
|
repo Manipulate the IPFS repository
|
|
stats Various operational stats
|
|
p2p Libp2p stream mounting
|
|
filestore Manage the filestore (experimental)
|
|
|
|
NETWORK COMMANDS
|
|
id Show info about IPFS peers
|
|
bootstrap Add or remove bootstrap peers
|
|
swarm Manage connections to the p2p network
|
|
dht Query the DHT for values or peers
|
|
ping Measure the latency of a connection
|
|
diag Print diagnostics
|
|
|
|
TOOL COMMANDS
|
|
config Manage configuration
|
|
version Show ipfs version information
|
|
update Download and apply go-ipfs updates
|
|
commands List all available commands
|
|
cid Convert and discover properties of CIDs
|
|
|
|
Use 'ipfs <command> --help' to learn more about each command.
|
|
|
|
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
|
|
|
|
EXIT STATUS
|
|
|
|
The CLI will exit with one of the following values:
|
|
|
|
0 Successful execution.
|
|
1 Failed executions.
|
|
`,
|
|
},
|
|
Options: []cmdkit.Option{
|
|
cmdkit.StringOption(ConfigOption, "c", "Path to the configuration file to use."),
|
|
cmdkit.BoolOption(DebugOption, "D", "Operate in debug mode."),
|
|
cmdkit.BoolOption(cmds.OptLongHelp, "Show the full command help text."),
|
|
cmdkit.BoolOption(cmds.OptShortHelp, "Show a short version of the command help text."),
|
|
cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon."),
|
|
cmdkit.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
|
|
|
|
// global options, added to every command
|
|
cmds.OptionEncodingType,
|
|
cmds.OptionStreamChannels,
|
|
cmds.OptionTimeout,
|
|
},
|
|
}
|
|
|
|
// commandsDaemonCmd is the "ipfs commands" command for daemon
|
|
var CommandsDaemonCmd = CommandsCmd(Root)
|
|
|
|
var rootSubcommands = map[string]*cmds.Command{
|
|
"add": AddCmd,
|
|
"bitswap": BitswapCmd,
|
|
"block": BlockCmd,
|
|
"cat": CatCmd,
|
|
"commands": CommandsDaemonCmd,
|
|
"files": FilesCmd,
|
|
"filestore": FileStoreCmd,
|
|
"get": GetCmd,
|
|
"pubsub": PubsubCmd,
|
|
"repo": RepoCmd,
|
|
"stats": StatsCmd,
|
|
"bootstrap": lgc.NewCommand(BootstrapCmd),
|
|
"config": lgc.NewCommand(ConfigCmd),
|
|
"dag": dag.DagCmd,
|
|
"dht": DhtCmd,
|
|
"diag": DiagCmd,
|
|
"dns": DNSCmd,
|
|
"id": IDCmd,
|
|
"key": KeyCmd,
|
|
"log": lgc.NewCommand(LogCmd),
|
|
"ls": lgc.NewCommand(LsCmd),
|
|
"mount": lgc.NewCommand(MountCmd),
|
|
"name": name.NameCmd,
|
|
"object": ocmd.ObjectCmd,
|
|
"pin": lgc.NewCommand(PinCmd),
|
|
"ping": PingCmd,
|
|
"p2p": P2PCmd,
|
|
"refs": lgc.NewCommand(RefsCmd),
|
|
"resolve": ResolveCmd,
|
|
"swarm": SwarmCmd,
|
|
"tar": TarCmd,
|
|
"file": lgc.NewCommand(unixfs.UnixFSCmd),
|
|
"update": lgc.NewCommand(ExternalBinary()),
|
|
"urlstore": urlStoreCmd,
|
|
"version": VersionCmd,
|
|
"shutdown": daemonShutdownCmd,
|
|
"cid": CidCmd,
|
|
}
|
|
|
|
// RootRO is the readonly version of Root
|
|
var RootRO = &cmds.Command{}
|
|
|
|
var CommandsDaemonROCmd = CommandsCmd(RootRO)
|
|
|
|
var RefsROCmd = &oldcmds.Command{}
|
|
|
|
var rootROSubcommands = map[string]*cmds.Command{
|
|
"commands": CommandsDaemonROCmd,
|
|
"cat": CatCmd,
|
|
"block": &cmds.Command{
|
|
Subcommands: map[string]*cmds.Command{
|
|
"stat": blockStatCmd,
|
|
"get": blockGetCmd,
|
|
},
|
|
},
|
|
"get": GetCmd,
|
|
"dns": DNSCmd,
|
|
"ls": lgc.NewCommand(LsCmd),
|
|
"name": {
|
|
Subcommands: map[string]*cmds.Command{
|
|
"resolve": name.IpnsCmd,
|
|
},
|
|
},
|
|
"object": {
|
|
Subcommands: map[string]*cmds.Command{
|
|
"data": ocmd.ObjectDataCmd,
|
|
"links": ocmd.ObjectLinksCmd,
|
|
"get": ocmd.ObjectGetCmd,
|
|
"stat": ocmd.ObjectStatCmd,
|
|
},
|
|
},
|
|
"dag": {
|
|
Subcommands: map[string]*cmds.Command{
|
|
"get": dag.DagGetCmd,
|
|
"resolve": dag.DagResolveCmd,
|
|
},
|
|
},
|
|
"resolve": ResolveCmd,
|
|
"version": VersionCmd,
|
|
}
|
|
|
|
func init() {
|
|
Root.ProcessHelp()
|
|
*RootRO = *Root
|
|
|
|
// sanitize readonly refs command
|
|
*RefsROCmd = *RefsCmd
|
|
RefsROCmd.Subcommands = map[string]*oldcmds.Command{}
|
|
|
|
// this was in the big map definition above before,
|
|
// but if we leave it there lgc.NewCommand will be executed
|
|
// before the value is updated (:/sanitize readonly refs command/)
|
|
rootROSubcommands["refs"] = lgc.NewCommand(RefsROCmd)
|
|
|
|
Root.Subcommands = rootSubcommands
|
|
|
|
RootRO.Subcommands = rootROSubcommands
|
|
}
|
|
|
|
type MessageOutput struct {
|
|
Message string
|
|
}
|
|
|
|
func MessageTextMarshaler(res oldcmds.Response) (io.Reader, error) {
|
|
v, err := unwrapOutput(res.Output())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
out, ok := v.(*MessageOutput)
|
|
if !ok {
|
|
return nil, e.TypeErr(out, v)
|
|
}
|
|
|
|
return strings.NewReader(out.Message), nil
|
|
}
|