mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-20 08:27:29 +08:00

* reduces help indent from 4 to 2 spaces License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * reduces horz/vert space taken by "ipfs" cmd License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * show subcommands on shorthelp License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Drops colons at the end of cmd headings. This makes command headings consistent with the output of 'ipfs', which does not include colons. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * more consistent output between short-/long-help License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Puts DESCRIPTION before SUBCOMMANDS. Users likely want to understand what a command does before worrying about its subcommands. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Keeps ipfs cmd from outputting its subcmds twice. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant synopsis from "file" License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes extra whitespace from longhelp License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Consistent spacing whether SUBCMDS or not. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant SUBCMD output from ipfs object. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant synopsis from "name" License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Newline after Description only if it exists. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant synopsis from "bootstrap" License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant synopsis from "swarm" License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes trailing newline in ping help. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Prints shorthelp on parse error. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * tiny comment fixes License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * updates README usage License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Don't include extra whitespace if no .MoreHelp License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * description improvements License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Hides the obscure 'file' subcommand. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Splits 'ipfs daemon' into Short and Long help. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes redundant synopsis from "config" License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Wraps lines to keep from going over 80. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * specify repo separately License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * s/structure/hierarchy License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * missing . License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes trailing colon from 'usage' test. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Updates sharness test error messages. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes trailing colon from 'usage' test. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Updates add-symlink to use /bin/sh. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Removes "hierarchy". License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io> * Updates "ipfs ping" synopsis. * Updates t0040 with latest wording. * Removes unnecessary daemon setup. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io>
173 lines
4.7 KiB
Go
173 lines
4.7 KiB
Go
package commands
|
|
|
|
import (
|
|
"io"
|
|
"strings"
|
|
|
|
cmds "github.com/ipfs/go-ipfs/commands"
|
|
files "github.com/ipfs/go-ipfs/core/commands/files"
|
|
ocmd "github.com/ipfs/go-ipfs/core/commands/object"
|
|
unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
|
|
logging "gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log"
|
|
)
|
|
|
|
var log = logging.Logger("core/commands")
|
|
|
|
const (
|
|
ApiOption = "api"
|
|
)
|
|
|
|
var Root = &cmds.Command{
|
|
Helptext: cmds.HelpText{
|
|
Tagline: "Global p2p merkle-dag filesystem.",
|
|
Synopsis: `
|
|
ipfs [<flags>] <command> [<arg>] ...
|
|
`,
|
|
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
|
|
|
|
ADVANCED COMMANDS
|
|
daemon Start a long-running daemon process
|
|
mount Mount an ipfs read-only mountpoint
|
|
resolve Resolve any type of name
|
|
name Publish or resolve IPNS names
|
|
dns Resolve DNS links
|
|
pin Pin objects to local storage
|
|
repo Manipulate the IPFS repository
|
|
|
|
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
|
|
|
|
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
|
|
`,
|
|
},
|
|
Options: []cmds.Option{
|
|
cmds.StringOption("config", "c", "Path to the configuration file to use."),
|
|
cmds.BoolOption("debug", "D", "Operate in debug mode."),
|
|
cmds.BoolOption("help", "Show the full command help text."),
|
|
cmds.BoolOption("h", "Show a short version of the command help text."),
|
|
cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon."),
|
|
cmds.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
|
|
},
|
|
}
|
|
|
|
// commandsDaemonCmd is the "ipfs commands" command for daemon
|
|
var CommandsDaemonCmd = CommandsCmd(Root)
|
|
|
|
var rootSubcommands = map[string]*cmds.Command{
|
|
"add": AddCmd,
|
|
"block": BlockCmd,
|
|
"bootstrap": BootstrapCmd,
|
|
"cat": CatCmd,
|
|
"commands": CommandsDaemonCmd,
|
|
"config": ConfigCmd,
|
|
"dht": DhtCmd,
|
|
"diag": DiagCmd,
|
|
"dns": DNSCmd,
|
|
"files": files.FilesCmd,
|
|
"get": GetCmd,
|
|
"id": IDCmd,
|
|
"log": LogCmd,
|
|
"ls": LsCmd,
|
|
"mount": MountCmd,
|
|
"name": NameCmd,
|
|
"object": ocmd.ObjectCmd,
|
|
"pin": PinCmd,
|
|
"ping": PingCmd,
|
|
"refs": RefsCmd,
|
|
"repo": RepoCmd,
|
|
"resolve": ResolveCmd,
|
|
"stats": StatsCmd,
|
|
"swarm": SwarmCmd,
|
|
"tar": TarCmd,
|
|
"tour": tourCmd,
|
|
"file": unixfs.UnixFSCmd,
|
|
"update": ExternalBinary(),
|
|
"version": VersionCmd,
|
|
"bitswap": BitswapCmd,
|
|
}
|
|
|
|
// RootRO is the readonly version of Root
|
|
var RootRO = &cmds.Command{}
|
|
|
|
var CommandsDaemonROCmd = CommandsCmd(RootRO)
|
|
|
|
var RefsROCmd = &cmds.Command{}
|
|
|
|
var rootROSubcommands = map[string]*cmds.Command{
|
|
"block": &cmds.Command{
|
|
Subcommands: map[string]*cmds.Command{
|
|
"stat": blockStatCmd,
|
|
"get": blockGetCmd,
|
|
},
|
|
},
|
|
"cat": CatCmd,
|
|
"commands": CommandsDaemonROCmd,
|
|
"dns": DNSCmd,
|
|
"get": GetCmd,
|
|
"ls": LsCmd,
|
|
"name": &cmds.Command{
|
|
Subcommands: map[string]*cmds.Command{
|
|
"resolve": IpnsCmd,
|
|
},
|
|
},
|
|
"object": &cmds.Command{
|
|
Subcommands: map[string]*cmds.Command{
|
|
"data": ocmd.ObjectDataCmd,
|
|
"links": ocmd.ObjectLinksCmd,
|
|
"get": ocmd.ObjectGetCmd,
|
|
"stat": ocmd.ObjectStatCmd,
|
|
"patch": ocmd.ObjectPatchCmd,
|
|
},
|
|
},
|
|
"refs": RefsROCmd,
|
|
"resolve": ResolveCmd,
|
|
"version": VersionCmd,
|
|
}
|
|
|
|
func init() {
|
|
*RootRO = *Root
|
|
|
|
// sanitize readonly refs command
|
|
*RefsROCmd = *RefsCmd
|
|
RefsROCmd.Subcommands = map[string]*cmds.Command{}
|
|
|
|
Root.Subcommands = rootSubcommands
|
|
RootRO.Subcommands = rootROSubcommands
|
|
}
|
|
|
|
type MessageOutput struct {
|
|
Message string
|
|
}
|
|
|
|
func MessageTextMarshaler(res cmds.Response) (io.Reader, error) {
|
|
return strings.NewReader(res.Output().(*MessageOutput).Message), nil
|
|
}
|