From b691e1707c608b2c2fc33c317f0bef75b8f247a0 Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Fri, 18 Mar 2016 12:47:13 -0400 Subject: [PATCH] Add programatic defaults Also fixed up a few spelling errors and mistypes, here and there. Got everything I could find. License: MIT Signed-off-by: Richard Littauer --- cmd/ipfs/daemon.go | 18 +++++++++--------- cmd/ipfs/init.go | 6 +++--- core/commands/active.go | 2 +- core/commands/add.go | 18 +++++++++--------- core/commands/bitswap.go | 2 +- core/commands/bootstrap.go | 4 ++-- core/commands/commands.go | 2 +- core/commands/config.go | 4 ++-- core/commands/dht.go | 8 ++++---- core/commands/diag.go | 11 ++++++----- core/commands/dns.go | 2 +- core/commands/external.go | 6 +++--- core/commands/files/files.go | 20 ++++++++++---------- core/commands/get.go | 8 ++++---- core/commands/ipns.go | 7 ++++--- core/commands/ls.go | 2 +- core/commands/mount_unix.go | 4 ++-- core/commands/object/object.go | 6 +++--- core/commands/object/patch.go | 2 +- core/commands/pin.go | 16 ++++++++++++---- core/commands/ping.go | 2 +- core/commands/publish.go | 8 ++++---- core/commands/refs.go | 8 ++++---- core/commands/repo.go | 4 ++-- core/commands/resolve.go | 2 +- core/commands/root.go | 12 ++++++------ core/commands/stat.go | 8 ++++---- core/commands/swarm.go | 2 +- core/commands/tour.go | 2 +- core/commands/version.go | 6 +++--- 30 files changed, 106 insertions(+), 96 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 89df66e755b..3cbbe46a2c2 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -122,15 +122,15 @@ future version, along with this notice. Please move to setting the HTTP Headers. }, Options: []cmds.Option{ - cmds.BoolOption(initOptionKwd, "Initialize IPFS with default settings if not already initialized"), - cmds.StringOption(routingOptionKwd, "Overrides the routing option (dht, supernode)"), - cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"), - cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"), - cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"), - cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"), - cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes"), - cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"), - cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"), + cmds.BoolOption(initOptionKwd, "Initialize IPFS with default settings if not already initialized").Default(false), + cmds.StringOption(routingOptionKwd, "Overrides the routing option (dht, supernode)").Default(false), + cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem").Default(false), + cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)").Default(false), + cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)").Default("/ipfs"), + cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)").Default("/ipns"), + cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes").Default(true), + cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)").Default(false), + cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false), // TODO: add way to override addresses. tricky part: updating the config if also --init. // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"), diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index 2861901fb97..130fa216274 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -34,9 +34,9 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable }, Options: []cmds.Option{ - cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)), - cmds.BoolOption("force", "f", "Overwrite existing config (if it exists)."), - cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage."), + cmds.IntOption("bits", "b", "Number of bits to use in the generated RSA private key").Default(fmt.Sprintf("%d", nBitsForKeypairDefault)), + cmds.BoolOption("force", "f", "Overwrite existing config (if it exists).").Default(false), + cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage.").Default(false), // TODO need to decide whether to expose the override as a file or a // directory. That is: should we allow the user to also specify the diff --git a/core/commands/active.go b/core/commands/active.go index 8f6876b6288..37da1d61a61 100644 --- a/core/commands/active.go +++ b/core/commands/active.go @@ -22,7 +22,7 @@ Lists running and recently run commands. res.SetOutput(req.InvocContext().ReqLog.Report()) }, Options: []cmds.Option{ - cmds.BoolOption("v", "verbose", "print more verbose output"), + cmds.BoolOption("v", "verbose", "print more verbose output").Default(false), }, Subcommands: map[string]*cmds.Command{ "clear": clearInactiveCmd, diff --git a/core/commands/add.go b/core/commands/add.go index 814afc9dfc9..abb53a78ee1 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -43,15 +43,15 @@ MerkleDAG. }, Options: []cmds.Option{ cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive) - cmds.BoolOption(quietOptionName, "q", "Write minimal output."), - cmds.BoolOption(silentOptionName, "Write no output."), - cmds.BoolOption(progressOptionName, "p", "Stream progress data."), - cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."), - cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."), - cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."), - cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."), - cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."), - cmds.BoolOption(pinOptionName, "Pin this object when adding. Default: true."), + cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false), + cmds.BoolOption(silentOptionName, "Write no output.").Default(false), + cmds.BoolOption(progressOptionName, "p", "Stream progress data.").Default(false), + cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false), + cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false), + cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false), + cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false), + cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use.").Default(false), + cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true), }, PreRun: func(req cmds.Request) error { if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet { diff --git a/core/commands/bitswap.go b/core/commands/bitswap.go index 94bb7a1158f..e02729054d4 100644 --- a/core/commands/bitswap.go +++ b/core/commands/bitswap.go @@ -73,7 +73,7 @@ var showWantlistCmd = &cmds.Command{ Print out all blocks currently on the bitswap wantlist for the local peer.`, }, Options: []cmds.Option{ - cmds.StringOption("peer", "p", "Specify which peer to show wantlist for. Default: self."), + cmds.StringOption("peer", "p", "Specify which peer to show wantlist for.").Default("self"), }, Type: KeyList{}, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/bootstrap.go b/core/commands/bootstrap.go index eb3745d2697..4df47e51c7c 100644 --- a/core/commands/bootstrap.go +++ b/core/commands/bootstrap.go @@ -56,7 +56,7 @@ in the bootstrap list). }, Options: []cmds.Option{ - cmds.BoolOption("default", "Add default bootstrap nodes."), + cmds.BoolOption("default", "Add default bootstrap nodes.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { @@ -137,7 +137,7 @@ var bootstrapRemoveCmd = &cmds.Command{ cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("all", "Remove all bootstrap peers."), + cmds.BoolOption("all", "Remove all bootstrap peers.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { input, err := config.ParseBootstrapPeers(req.Arguments()) diff --git a/core/commands/commands.go b/core/commands/commands.go index 046ff785abb..3d43a2186d7 100644 --- a/core/commands/commands.go +++ b/core/commands/commands.go @@ -34,7 +34,7 @@ func CommandsCmd(root *cmds.Command) *cmds.Command { ShortDescription: `Lists all available commands (and subcommands) and exits.`, }, Options: []cmds.Option{ - cmds.BoolOption(flagsOptionName, "f", "Show command flags"), + cmds.BoolOption(flagsOptionName, "f", "Show command flags").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { showOptions, _, _ := req.Option(flagsOptionName).Bool() diff --git a/core/commands/config.go b/core/commands/config.go index c66c148408a..c0708a12de5 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -58,8 +58,8 @@ Set the value of the 'datastore.path' key: cmds.StringArg("value", false, false, "The value to set the config entry to."), }, Options: []cmds.Option{ - cmds.BoolOption("bool", "Set a boolean value. Default: false."), - cmds.BoolOption("json", "Parse stringified JSON. Default: false."), + cmds.BoolOption("bool", "Set a boolean value.").Default(false), + cmds.BoolOption("json", "Parse stringified JSON.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { args := req.Arguments() diff --git a/core/commands/dht.go b/core/commands/dht.go index 3bc16170c2f..17bbd91ee70 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -43,7 +43,7 @@ var queryDhtCmd = &cmds.Command{ cmds.StringArg("peerID", true, true, "The peerID to run the query against."), }, Options: []cmds.Option{ - cmds.BoolOption("verbose", "v", "Write extra information."), + cmds.BoolOption("verbose", "v", "Write extra information.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -129,7 +129,7 @@ FindProviders will return a list of peers who are able to provide the value requ cmds.StringArg("key", true, true, "The key to find providers for."), }, Options: []cmds.Option{ - cmds.BoolOption("verbose", "v", "Write extra information."), + cmds.BoolOption("verbose", "v", "Write extra information.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -327,7 +327,7 @@ GetValue will return the value stored in the DHT at the given key. cmds.StringArg("key", true, true, "The key to find a value for."), }, Options: []cmds.Option{ - cmds.BoolOption("verbose", "v", "Write extra information."), + cmds.BoolOption("verbose", "v", "Write extra information.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -431,7 +431,7 @@ PutValue will store the given key value pair in the DHT. cmds.StringArg("value", true, false, "The value to store.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("verbose", "v", "Write extra information."), + cmds.BoolOption("verbose", "v", "Write extra information.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() diff --git a/core/commands/diag.go b/core/commands/diag.go index f3c2a32c6c3..8857d167e50 100644 --- a/core/commands/diag.go +++ b/core/commands/diag.go @@ -22,7 +22,8 @@ type DiagnosticConnection struct { var ( visD3 = "d3" visDot = "dot" - visFmts = []string{visD3, visDot} + visText = "text" + visFmts = []string{visD3, visDot, visText} ) type DiagnosticPeer struct { @@ -66,8 +67,8 @@ timeout. If the timeout is too small, some peers may not be reached. The default timeout is 20 seconds. The 'vis' option may be used to change the output format. -Four formats are supported: - * plain text - Easy to read. Default. +Three formats are supported: + * text - Easy to read. Default. * d3 - json ready to be fed into d3view * dot - graphviz format @@ -81,13 +82,13 @@ open the following link: http://gateway.ipfs.io/ipfs/QmbesKpGyQGd5jtJFUGEB1ByPjNFpukhnKZDnkfxUiKn38/chord# -The dot format can be fed into graphviz and other programs +The 'dot' format can be fed into graphviz and other programs that consume the dot format to generate graphs of the network. `, }, Options: []cmds.Option{ - cmds.StringOption("vis", "Output vis. One of: "+strings.Join(visFmts, ", ")), + cmds.StringOption("vis", "Output format. One of: "+strings.Join(visFmts, ", ")).Default("text"), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/dns.go b/core/commands/dns.go index 00b96fbb94d..3468aed2a19 100644 --- a/core/commands/dns.go +++ b/core/commands/dns.go @@ -47,7 +47,7 @@ The resolver can recursively resolve: cmds.StringArg("domain-name", true, false, "The domain-name name to resolve.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link. Default: false."), + cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/external.go b/core/commands/external.go index c49fc13c906..6241b9f7d5a 100644 --- a/core/commands/external.go +++ b/core/commands/external.go @@ -26,8 +26,8 @@ func ExternalBinary() *cmds.Command { if arg == "--help" || arg == "-h" { buf := new(bytes.Buffer) fmt.Fprintf(buf, "%s is an 'external' command.\n", binname) - fmt.Fprintf(buf, "it does not currently appear to be installed.\n") - fmt.Fprintf(buf, "please refer to the ipfs documentation for instructions\n") + fmt.Fprintf(buf, "It does not currently appear to be installed.\n") + fmt.Fprintf(buf, "Please refer to the ipfs documentation for instructions.\n") res.SetOutput(buf) return } @@ -59,7 +59,7 @@ func ExternalBinary() *cmds.Command { err = cmd.Start() if err != nil { - res.SetError(fmt.Errorf("failed to start subcommand: %s", err), cmds.ErrNormal) + res.SetError(fmt.Errorf("Failed to start subcommand: %s", err), cmds.ErrNormal) return } diff --git a/core/commands/files/files.go b/core/commands/files/files.go index 913a89dc176..eb38f7e8fa4 100644 --- a/core/commands/files/files.go +++ b/core/commands/files/files.go @@ -38,7 +38,7 @@ on the files in question, then data may be lost. This also applies to running `, }, Options: []cmds.Option{ - cmds.BoolOption("f", "flush", "Flush target and ancestors after write. Default: true."), + cmds.BoolOption("f", "flush", "Flush target and ancestors after write.").Default(true), }, Subcommands: map[string]*cmds.Command{ "read": FilesReadCmd, @@ -249,10 +249,10 @@ Examples: `, }, Arguments: []cmds.Argument{ - cmds.StringArg("path", false, false, "Path to show listing for. Defaults to '/'."), + cmds.StringArg("path", false, false, "Path to show listing for.").Default('/'), }, Options: []cmds.Option{ - cmds.BoolOption("l", "Use long listing format."), + cmds.BoolOption("l", "Use long listing format.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { var arg string @@ -348,7 +348,7 @@ Examples: cmds.StringArg("path", true, false, "Path to file to be read."), }, Options: []cmds.Option{ - cmds.IntOption("o", "offset", "Byte offset to begin reading from."), + cmds.IntOption("o", "offset", "Byte offset to begin reading from.").Default(false), cmds.IntOption("n", "count", "Maximum number of bytes to read."), }, Run: func(req cmds.Request, res cmds.Response) { @@ -516,9 +516,9 @@ Warning: cmds.FileArg("data", true, false, "Data to write.").EnableStdin(), }, Options: []cmds.Option{ - cmds.IntOption("o", "offset", "Byte offset to begin writing at."), - cmds.BoolOption("e", "create", "Create the file if it does not exist."), - cmds.BoolOption("t", "truncate", "Truncate the file to size zero before writing."), + cmds.IntOption("o", "offset", "Byte offset to begin writing at.").Default(0), + cmds.BoolOption("e", "create", "Create the file if it does not exist.").Default(false), + cmds.BoolOption("t", "truncate", "Truncate the file to size zero before writing.").Default(false), cmds.IntOption("n", "count", "Maximum number of bytes to read."), }, Run: func(req cmds.Request, res cmds.Response) { @@ -629,7 +629,7 @@ Examples: cmds.StringArg("path", true, false, "Path to dir to make."), }, Options: []cmds.Option{ - cmds.BoolOption("p", "parents", "No error if existing, make parent directories as needed."), + cmds.BoolOption("p", "parents", "No error if existing, make parent directories as needed.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -668,7 +668,7 @@ are run with the '--flush=false'. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("path", false, false, "Path to flush. Default: '/'."), + cmds.StringArg("path", false, false, "Path to flush.").Default("/"), }, Run: func(req cmds.Request, res cmds.Response) { nd, err := req.InvocContext().GetNode() @@ -709,7 +709,7 @@ Remove files or directories. cmds.StringArg("path", true, true, "File to remove."), }, Options: []cmds.Option{ - cmds.BoolOption("r", "recursive", "Recursively remove directories."), + cmds.BoolOption("r", "recursive", "Recursively remove directories.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { nd, err := req.InvocContext().GetNode() diff --git a/core/commands/get.go b/core/commands/get.go index 12a88cd7c29..dbe1f1a5bd5 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -40,10 +40,10 @@ may also specify the level of compression by specifying '-l=<1-9>'. cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted.").EnableStdin(), }, Options: []cmds.Option{ - cmds.StringOption("output", "o", "The path where the output should be stored."), - cmds.BoolOption("archive", "a", "Output a TAR archive. Default: false."), - cmds.BoolOption("compress", "C", "Compress the output with GZIP compression. Default: false."), - cmds.IntOption("compression-level", "l", "The level of compression (1-9). Default: -1."), + cmds.StringOption("output", "o", "The path where the output should be stored.").Default("'./'"), + cmds.BoolOption("archive", "a", "Output a TAR archive.").Default(false), + cmds.BoolOption("compress", "C", "Compress the output with GZIP compression.").Default(false), + cmds.IntOption("compression-level", "l", "The level of compression (1-9).").Default("-1"), }, PreRun: func(req cmds.Request) error { _, err := getCompressOptions(req) diff --git a/core/commands/ipns.go b/core/commands/ipns.go index 063a9835068..640a4e8d0a7 100644 --- a/core/commands/ipns.go +++ b/core/commands/ipns.go @@ -41,11 +41,12 @@ Resolve the value of another name: }, Arguments: []cmds.Argument{ - cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID.").EnableStdin(), + cmds.StringArg("name", false, false, "The IPNS name to resolve.").EnableStdin().Default("your node's peerID"), }, Options: []cmds.Option{ - cmds.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name."), - cmds.BoolOption("nocache", "n", "Do not used cached entries."), + cmds.BoolOption("recursive", "r", "Resolve until the result is not an IPNS name.").Default(false), + cmds.BoolOption("nocache", "n", "Do not use cached entries.").Default(false), + cmds.BoolOption("local", "l", "Use only local entires").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/ls.go b/core/commands/ls.go index 5aa3b6513d2..9604a1d2d91 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -43,7 +43,7 @@ Displays the links an IPFS or IPNS object(s) contains, with the following format cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."), + cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { node, err := req.InvocContext().GetNode() diff --git a/core/commands/mount_unix.go b/core/commands/mount_unix.go index fbcd99b45e6..75d3bb0ead9 100644 --- a/core/commands/mount_unix.go +++ b/core/commands/mount_unix.go @@ -73,8 +73,8 @@ baz `, }, Options: []cmds.Option{ - cmds.StringOption("ipfs-path", "f", "The path where IPFS should be mounted."), - cmds.StringOption("ipns-path", "n", "The path where IPNS should be mounted."), + cmds.StringOption("ipfs-path", "f", "The path where IPFS should be mounted.").Default("'/ipfs'"), + cmds.StringOption("ipns-path", "n", "The path where IPNS should be mounted.").Default("'/ipns'"), }, Run: func(req cmds.Request, res cmds.Response) { cfg, err := req.InvocContext().GetConfig() diff --git a/core/commands/object/object.go b/core/commands/object/object.go index 86091ad0727..fd6a232dc68 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -120,7 +120,7 @@ multihash. cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."), + cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -341,7 +341,7 @@ And then run: cmds.FileArg("data", true, false, "Data to be stored as a DAG object.").EnableStdin(), }, Options: []cmds.Option{ - cmds.StringOption("inputenc", "Encoding type of input data, either \"protobuf\" or \"json\"."), + cmds.StringOption("inputenc", "Encoding type of input data. One of: protobuf, json.").Default("json"), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -403,7 +403,7 @@ Available templates: `, }, Arguments: []cmds.Argument{ - cmds.StringArg("template", false, false, "Template to use. Optional."), + cmds.StringArg("template", false, false, "Template to use.").Default("false"), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() diff --git a/core/commands/object/patch.go b/core/commands/object/patch.go index 1180463ed71..2507e966987 100644 --- a/core/commands/object/patch.go +++ b/core/commands/object/patch.go @@ -247,7 +247,7 @@ a file containing 'bar', and returns the hash of the new object. `, }, Options: []cmds.Option{ - cmds.BoolOption("p", "create", "Create intermediary nodes."), + cmds.BoolOption("p", "create", "Create intermediary nodes.").Default(false), }, Arguments: []cmds.Argument{ cmds.StringArg("root", true, false, "The hash of the node to modify."), diff --git a/core/commands/pin.go b/core/commands/pin.go index 4bf250d0167..3b35a98a617 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "strings" key "github.com/ipfs/go-ipfs/blocks/key" cmds "github.com/ipfs/go-ipfs/commands" @@ -15,6 +16,14 @@ import ( context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) +var ( + tDirect = "direct" + tIndirect = "indirect" + tRecursive = "recursive" + tAll = "all" + tLists = []string{tDirect, tIndirect, tRecursive, tAll} +) + var PinCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Pin (and unpin) objects to local storage.", @@ -187,9 +196,8 @@ Example: cmds.StringArg("ipfs-path", false, true, "Path to object(s) to be listed."), }, Options: []cmds.Option{ - cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"recursive\"."), - cmds.BoolOption("count", "n", "Show refcount when listing indirect pins."), - cmds.BoolOption("quiet", "q", "Write just hashes of objects."), + cmds.StringOption("type", "t", "The type of pinned keys to list. One of: "+strings.Join(tLists, ", ")).Default("recursive"), + cmds.BoolOption("quiet", "q", "Write just hashes of objects.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -208,7 +216,7 @@ Example: switch typeStr { case "all", "direct", "indirect", "recursive": default: - err = fmt.Errorf("Invalid type '%s', must be one of {direct, indirect, recursive, all}", typeStr) + err = fmt.Errorf("Invalid type '%s', must be one of {"+strings.Join(tLists, ", ")+"}", typeStr) res.SetError(err, cmds.ErrClient) return } diff --git a/core/commands/ping.go b/core/commands/ping.go index afe568666a9..bb330cd0af6 100644 --- a/core/commands/ping.go +++ b/core/commands/ping.go @@ -41,7 +41,7 @@ trip latency information. cmds.StringArg("peer ID", true, true, "ID of peer to be pinged.").EnableStdin(), }, Options: []cmds.Option{ - cmds.IntOption("count", "n", "Number of ping messages to send."), + cmds.IntOption("count", "n", "Number of ping messages to send.").Default(10), }, Marshalers: cmds.MarshalerMap{ cmds.Text: func(res cmds.Response) (io.Reader, error) { diff --git a/core/commands/publish.go b/core/commands/publish.go index 35ec9c5ec42..c2bf596dda7 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -50,13 +50,13 @@ Publish an to another public key (not implemented): cmds.StringArg("ipfs-path", true, false, "IPFS path of the obejct to be published.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("resolve", "Resolve given path before publishing (default=true)."), - cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for. Default: 24h. + cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true), + cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for. This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". - `), - cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."), + `).Default("24h"), + cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental).").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { log.Debug("Begin Publish") diff --git a/core/commands/refs.go b/core/commands/refs.go index 73fd67da797..5c465436b2f 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -49,10 +49,10 @@ Note: List all references recursively by using the flag '-r'. cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from.").EnableStdin(), }, Options: []cmds.Option{ - cmds.StringOption("format", "Emit edges with given format. Available tokens: ."), - cmds.BoolOption("edges", "e", "Emit edge format: ` -> `."), - cmds.BoolOption("unique", "u", "Omit duplicate refs from output."), - cmds.BoolOption("recursive", "r", "Recursively list links of child nodes."), + cmds.StringOption("format", "Emit edges with given format. Available tokens: .").Default(""), + cmds.BoolOption("edges", "e", "Emit edge format: ` -> `.").Default(false), + cmds.BoolOption("unique", "u", "Omit duplicate refs from output.").Default(false), + cmds.BoolOption("recursive", "r", "Recursively list links of child nodes.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { ctx := req.Context() diff --git a/core/commands/repo.go b/core/commands/repo.go index e4ac8807d64..bbbebc66167 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -34,7 +34,7 @@ order to reclaim hard disk space. }, Options: []cmds.Option{ - cmds.BoolOption("quiet", "q", "Write minimal output."), + cmds.BoolOption("quiet", "q", "Write minimal output.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -123,7 +123,7 @@ RepoPath string the path to the repo being currently used res.SetOutput(stat) }, Options: []cmds.Option{ - cmds.BoolOption("human", "Output RepoSize in MiB."), + cmds.BoolOption("human", "Output RepoSize in MiB.").Default(false), }, Type: corerepo.Stat{}, Marshalers: cmds.MarshalerMap{ diff --git a/core/commands/resolve.go b/core/commands/resolve.go index e6a7e0fa4a2..f2d8c6589ae 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -58,7 +58,7 @@ Resolve the value of an IPFS DAG path: cmds.StringArg("name", true, false, "The name to resolve.").EnableStdin(), }, Options: []cmds.Option{ - cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name. Default: false."), + cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/root.go b/core/commands/root.go index bd33929663e..0f7305b427a 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -79,12 +79,12 @@ at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable `, }, 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)"), + cmds.StringOption("config", "c", "Path to the configuration file to use.").Default("~/.ipfs/config"), + cmds.BoolOption("debug", "D", "Operate in debug mode.").Default(false), + cmds.BoolOption("help", "Show the full command help text.").Default(false), + cmds.BoolOption("h", "Show a short version of the command help text.").Default(false), + cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon.").Default(false), + cmds.StringOption(ApiOption, "Use a specific API instance.").Default("/ip4/127.0.0.1/tcp/5001"), }, } diff --git a/core/commands/stat.go b/core/commands/stat.go index 2a59346a839..dd4727a46c4 100644 --- a/core/commands/stat.go +++ b/core/commands/stat.go @@ -33,10 +33,10 @@ var statBwCmd = &cmds.Command{ ShortDescription: ``, }, Options: []cmds.Option{ - cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for."), - cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for."), - cmds.BoolOption("poll", "Print bandwidth at an interval. Default: false."), - cmds.StringOption("interval", "i", "Time interval to wait between updating output."), + cmds.StringOption("peer", "p", "Specify a peer to print bandwidth for.").Default("overall bandwidth"), + cmds.StringOption("proto", "t", "Specify a protocol to print bandwidth for.").Default("all protocols"), + cmds.BoolOption("poll", "Print bandwidth at an interval.").Default(false), + cmds.StringOption("interval", "i", "Time interval to wait between updating output.").Default("1s"), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 67b7a71c333..41707da2cb7 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -159,7 +159,7 @@ var swarmAddrsLocalCmd = &cmds.Command{ `, }, Options: []cmds.Option{ - cmds.BoolOption("id", "Show peer ID in addresses."), + cmds.BoolOption("id", "Show peer ID in addresses.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { diff --git a/core/commands/tour.go b/core/commands/tour.go index e82bf1b34ba..1cdee39d4ec 100644 --- a/core/commands/tour.go +++ b/core/commands/tour.go @@ -25,7 +25,7 @@ IPFS very quickly. To start, run: }, Arguments: []cmds.Argument{ - cmds.StringArg("id", false, false, "The id of the topic you would like to tour."), + cmds.StringArg("id", false, false, "The id of the topic you would like to tour.").Default("The last accessed tour"), }, Subcommands: map[string]*cmds.Command{ "list": cmdIpfsTourList, diff --git a/core/commands/version.go b/core/commands/version.go index c8d3212e2e6..9604cecffe6 100644 --- a/core/commands/version.go +++ b/core/commands/version.go @@ -23,9 +23,9 @@ var VersionCmd = &cmds.Command{ }, Options: []cmds.Option{ - cmds.BoolOption("number", "n", "Only show the version number."), - cmds.BoolOption("commit", "Show the commit hash."), - cmds.BoolOption("repo", "Show repo version."), + cmds.BoolOption("number", "n", "Only show the version number.").Default(false), + cmds.BoolOption("commit", "Show the commit hash.").Default(false), + cmds.BoolOption("repo", "Show repo version.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { res.SetOutput(&VersionOutput{