From c468a4dbf5cc442713ed0eda5057bfdd8b8c74f9 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 11 Nov 2014 15:55:20 -0800 Subject: [PATCH] core/commands2: Use Argument constructors in commands --- cmd/ipfs2/tour.go | 3 +-- core/commands2/add.go | 2 +- core/commands2/block.go | 4 ++-- core/commands2/bootstrap.go | 4 ++-- core/commands2/cat.go | 3 +-- core/commands2/config.go | 6 ++---- core/commands2/log.go | 6 ++---- core/commands2/ls.go | 3 +-- core/commands2/object.go | 15 +++++---------- core/commands2/pin.go | 6 ++---- core/commands2/publish.go | 6 ++---- core/commands2/refs.go | 3 +-- core/commands2/resolve.go | 3 +-- 13 files changed, 23 insertions(+), 41 deletions(-) diff --git a/cmd/ipfs2/tour.go b/cmd/ipfs2/tour.go index 00b845601..9d3e1247b 100644 --- a/cmd/ipfs2/tour.go +++ b/cmd/ipfs2/tour.go @@ -22,8 +22,7 @@ IPFS very quickly. To start, run: `, Arguments: []cmds.Argument{ - cmds.Argument{"number", cmds.ArgString, false, false, - "The number of the topic you would like to tour"}, + cmds.StringArg("number", false, false, "The number of the topic you would like to tour"), }, Subcommands: map[string]*cmds.Command{ "list": cmdIpfsTourList, diff --git a/core/commands2/add.go b/core/commands2/add.go index 043ac32cb..4913b0d56 100644 --- a/core/commands2/add.go +++ b/core/commands2/add.go @@ -26,7 +26,7 @@ var addCmd = &cmds.Command{ cmds.BoolOption("recursive", "r", "Must be specified when adding directories"), }, Arguments: []cmds.Argument{ - cmds.Argument{"file", cmds.ArgFile, true, true, "The path to a file to be added to IPFS"}, + cmds.FileArg("file", true, true, "The path to a file to be added to IPFS"), }, Description: "Add an object to ipfs.", Help: `Adds contents of to ipfs. Use -r to add directories. diff --git a/core/commands2/block.go b/core/commands2/block.go index ef9e554a8..65097ab17 100644 --- a/core/commands2/block.go +++ b/core/commands2/block.go @@ -38,7 +38,7 @@ var blockGetCmd = &cmds.Command{ It outputs to stdout, and is a base58 encoded multihash.`, Arguments: []cmds.Argument{ - cmds.Argument{"key", cmds.ArgString, true, false, "The base58 multihash of an existing block to get"}, + cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get"), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node @@ -74,7 +74,7 @@ var blockPutCmd = &cmds.Command{ It reads from stdin, and is a base58 encoded multihash.`, Arguments: []cmds.Argument{ - cmds.Argument{"data", cmds.ArgFile, true, false, "The data to be stored as an IPFS block"}, + cmds.FileArg("data", true, false, "The data to be stored as an IPFS block"), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node diff --git a/core/commands2/bootstrap.go b/core/commands2/bootstrap.go index 9c6de75bb..dd0edb0b0 100644 --- a/core/commands2/bootstrap.go +++ b/core/commands2/bootstrap.go @@ -39,7 +39,7 @@ in the bootstrap list). ` + bootstrapSecurityWarning, Arguments: []cmds.Argument{ - cmds.Argument{"peer", cmds.ArgString, true, true, peerOptionDesc}, + cmds.StringArg("peer", true, true, peerOptionDesc), }, Run: func(req cmds.Request) (interface{}, error) { input, err := bootstrapInputToPeers(req.Arguments()) @@ -79,7 +79,7 @@ var bootstrapRemoveCmd = &cmds.Command{ ` + bootstrapSecurityWarning, Arguments: []cmds.Argument{ - cmds.Argument{"peer", cmds.ArgString, true, true, peerOptionDesc}, + cmds.StringArg("peer", true, true, peerOptionDesc), }, Run: func(req cmds.Request) (interface{}, error) { input, err := bootstrapInputToPeers(req.Arguments()) diff --git a/core/commands2/cat.go b/core/commands2/cat.go index e8c39a533..89384fe55 100644 --- a/core/commands2/cat.go +++ b/core/commands2/cat.go @@ -16,8 +16,7 @@ it contains. `, Arguments: []cmds.Argument{ - cmds.Argument{"ipfs-path", cmds.ArgString, true, true, - "The path to the IPFS object(s) to be outputted"}, + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted"), }, Run: func(req cmds.Request) (interface{}, error) { node := req.Context().Node diff --git a/core/commands2/config.go b/core/commands2/config.go index dd15653c7..59dcd77e1 100644 --- a/core/commands2/config.go +++ b/core/commands2/config.go @@ -31,10 +31,8 @@ var configCmd = &cmds.Command{ `, Arguments: []cmds.Argument{ - cmds.Argument{"key", cmds.ArgString, true, false, - "The key of the config entry (e.g. \"Addresses.API\")"}, - cmds.Argument{"value", cmds.ArgString, false, false, - "The value to set the config entry to"}, + cmds.StringArg("key", true, false, "The key of the config entry (e.g. \"Addresses.API\")"), + cmds.StringArg("value", false, false, "The value to set the config entry to"), }, Run: func(req cmds.Request) (interface{}, error) { args := req.Arguments() diff --git a/core/commands2/log.go b/core/commands2/log.go index 12a8a28f9..4ed3233ad 100644 --- a/core/commands2/log.go +++ b/core/commands2/log.go @@ -14,10 +14,8 @@ output of a running daemon. `, Arguments: []cmds.Argument{ - cmds.Argument{"subsystem", cmds.ArgString, true, false, - "the subsystem logging identifier. Use * for all subsystems."}, - cmds.Argument{"level", cmds.ArgString, true, false, - "one of: debug, info, notice, warning, error, critical"}, + cmds.StringArg("subsystem", true, false, "the subsystem logging identifier. Use * for all subsystems."), + cmds.StringArg("level", true, false, "one of: debug, info, notice, warning, error, critical"), }, Run: func(req cmds.Request) (interface{}, error) { args := req.Arguments() diff --git a/core/commands2/ls.go b/core/commands2/ls.go index 1849740b3..0850178a5 100644 --- a/core/commands2/ls.go +++ b/core/commands2/ls.go @@ -31,8 +31,7 @@ it contains, with the following format: `, Arguments: []cmds.Argument{ - cmds.Argument{"ipfs-path", cmds.ArgString, false, true, - "The path to the IPFS object(s) to list links from"}, + cmds.StringArg("ipfs-path", false, true, "The path to the IPFS object(s) to list links from"), }, Run: func(req cmds.Request) (interface{}, error) { node := req.Context().Node diff --git a/core/commands2/object.go b/core/commands2/object.go index 48908334f..48e1b27a3 100644 --- a/core/commands2/object.go +++ b/core/commands2/object.go @@ -44,8 +44,7 @@ output is the raw data of the object. `, Arguments: []cmds.Argument{ - cmds.Argument{"key", cmds.ArgString, true, false, - "Key of the object to retrieve, in base58-encoded multihash format"}, + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format"), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node @@ -65,8 +64,7 @@ var objectLinksCmd = &cmds.Command{ It outputs to stdout, and is a base58 encoded multihash.`, Arguments: []cmds.Argument{ - cmds.Argument{"key", cmds.ArgString, true, false, - "Key of the object to retrieve, in base58-encoded multihash format"}, + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format"), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node @@ -94,8 +92,7 @@ This command outputs data in the following encodings: (Specified by the "--encoding" or "-enc" flags)`, Arguments: []cmds.Argument{ - cmds.Argument{"key", cmds.ArgString, true, false, - "Key of the object to retrieve\n(in base58-encoded multihash format)"}, + cmds.StringArg("key", true, false, "Key of the object to retrieve\n(in base58-encoded multihash format)"), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node @@ -146,10 +143,8 @@ Data should be in the format specified by . `, Arguments: []cmds.Argument{ - cmds.Argument{"data", cmds.ArgFile, true, false, - "Data to be stored as a DAG object\nMust be encoded as specified in "}, - cmds.Argument{"encoding", cmds.ArgString, true, false, - "Encoding type of , either \"protobuf\" or \"json\""}, + cmds.FileArg("data", true, false, "Data to be stored as a DAG object\nMust be encoded as specified in "), + cmds.StringArg("encoding", true, false, "Encoding type of , either \"protobuf\" or \"json\""), }, Run: func(req cmds.Request) (interface{}, error) { n := req.Context().Node diff --git a/core/commands2/pin.go b/core/commands2/pin.go index 1d7930823..84e8c3749 100644 --- a/core/commands2/pin.go +++ b/core/commands2/pin.go @@ -25,8 +25,7 @@ on disk. `, Arguments: []cmds.Argument{ - cmds.Argument{"ipfs-path", cmds.ArgString, true, true, - "Path to object(s) to be pinned"}, + cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be pinned"), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Recursively pin the object linked to by the specified object(s)"), @@ -59,8 +58,7 @@ collected if needed. `, Arguments: []cmds.Argument{ - cmds.Argument{"ipfs-path", cmds.ArgString, true, true, - "Path to object(s) to be unpinned"}, + cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be unpinned"), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Recursively unpin the object linked to by the specified object(s)"), diff --git a/core/commands2/publish.go b/core/commands2/publish.go index e5c8c89bf..68c5d71c2 100644 --- a/core/commands2/publish.go +++ b/core/commands2/publish.go @@ -34,10 +34,8 @@ Publish a to another public key: `, Arguments: []cmds.Argument{ - cmds.Argument{"name", cmds.ArgString, false, false, - "The IPNS name to publish to. Defaults to your node's peerID"}, - cmds.Argument{"ipfs-path", cmds.ArgString, true, false, - "IPFS path of the obejct to be published at "}, + cmds.StringArg("name", false, false, "The IPNS name to publish to. Defaults to your node's peerID"), + cmds.StringArg("ipfs-path", true, false, "IPFS path of the obejct to be published at "), }, Run: func(req cmds.Request) (interface{}, error) { log.Debug("Begin Publish") diff --git a/core/commands2/refs.go b/core/commands2/refs.go index a72324fd4..9efc06b54 100644 --- a/core/commands2/refs.go +++ b/core/commands2/refs.go @@ -25,8 +25,7 @@ hashes it contains, with the following format: Note: list all refs recursively with -r.`, Arguments: []cmds.Argument{ - cmds.Argument{"ipfs-path", cmds.ArgString, true, true, - "Path to the object(s) to list refs from"}, + cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from"), }, Options: []cmds.Option{ cmds.BoolOption("unique", "u", "Omit duplicate refs from output"), diff --git a/core/commands2/resolve.go b/core/commands2/resolve.go index f41c0c1d3..422ee32ee 100644 --- a/core/commands2/resolve.go +++ b/core/commands2/resolve.go @@ -28,8 +28,7 @@ Resolve te value of another name: `, Arguments: []cmds.Argument{ - cmds.Argument{"name", cmds.ArgString, false, false, - "The IPNS name to resolve. Defaults to your node's peerID."}, + cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID."), }, Run: func(req cmds.Request) (interface{}, error) {